OpenRISC fixes
cover OpenRISC fixes
I sent the fix for 90363 previously with the FPU patches. Now, I have added tests and another issue came up, so I am sending as a new series. I planned to commit the code before the 9.x release but missed that.
This is a series of fixes for the OpenRISC target found during recent testings.
PRs:
- 90362 or1k: Soft divide does not work correctly
- 90363 or1k: Extra mask insn after load from memory
Stafford Horne (2):
or1k: Fix code quality for volatile memory loads
or1k: Fix issues with msoft-div
gcc/config/or1k/or1k.md | 6 +- gcc/config/or1k/predicates.md | 18 +++++ gcc/testsuite/gcc.target/or1k/div-mul-3.c | 31 ++++++++ gcc/testsuite/gcc.target/or1k/swap-1.c | 86 +++++++++++++++++++++++ gcc/testsuite/gcc.target/or1k/swap-2.c | 63 +++++++++++++++++ libgcc/config/or1k/lib1funcs.S | 6 +- 6 files changed, 204 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.target/or1k/div-mul-3.c create mode 100644 gcc/testsuite/gcc.target/or1k/swap-1.c create mode 100644 gcc/testsuite/gcc.target/or1k/swap-2.c
Signature · 1 line
2.19.1
PATCH 1/2 or1k: Fix code quality for volatile memory loads
Volatile memory does not match the memory_operand predicate. This causes extra extend/mask instructions instructions when reading from volatile memory. On OpenRISC loading volitile memory can be treated the same as regular memory loads which supports combined sign/zero extends. Fixing this eliminates the need for extra extend/mask instructions.
This also adds a test provided by Richard Selvaggi which uncovered the issue while we were looking into another issue.
gcc/ChangeLog:
PR target/90363
* config/or1k/or1k.md (zero_extend<mode>si2): Update predicate. (extend<mode>si2): Update predicate.
* gcc/config/or1k/predicates.md (volatile_mem_operand): New. (reg_or_mem_operand): New.
gcc/testsuite/ChangeLog:
PR target/90363
* gcc.target/or1k/swap-1.c: New test.
* gcc.target/or1k/swap-2.c: New test.
--- gcc/config/or1k/or1k.md | 6 +- gcc/config/or1k/predicates.md | 18 ++++++ gcc/testsuite/gcc.target/or1k/swap-1.c | 86 ++++++++++++++++++++++++++ gcc/testsuite/gcc.target/or1k/swap-2.c | 63 +++++++++++++++++++ 4 files changed, 170 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/or1k/swap-1.c create mode 100644 gcc/testsuite/gcc.target/or1k/swap-2.c
gcc/config/or1k/or1k.md +3 -3
@@ -328,11 +328,11 @@ ;; Sign Extending ;; ------------------------------------------------------------------------- -;; Zero extension can always be done with AND and an extending load. +;; Zero extension can always be done with AND or an extending load. (define_insn "zero_extend<mode>si2" [(set (match_operand:SI 0 "register_operand" "=r,r") - (zero_extend:SI (match_operand:I12 1 "nonimmediate_operand" "r,m")))] + (zero_extend:SI (match_operand:I12 1 "reg_or_mem_operand" "r,m")))] "" "@ l.andi\t%0, %1, <zext_andi>
@@ -344,7 +344,7 @@ (define_insn "extend<mode>si2" [(set (match_operand:SI 0 "register_operand" "=r,r") - (sign_extend:SI (match_operand:I12 1 "nonimmediate_operand" "r,m")))] + (sign_extend:SI (match_operand:I12 1 "reg_or_mem_operand" "r,m")))] "TARGET_SEXT" "@ l.ext<ldst>s\t%0, %1
gcc/config/or1k/predicates.md +18 -0
@@ -82,3 +82,21 @@ (define_predicate "equality_comparison_operator" (match_code "ne,eq")) + +;; Borrowed from rs6000 +; Return true if the operand is in volatile memory. Note that during the +;; RTL generation phase, memory_operand does not return TRUE for volatile +;; memory references. So this function allows us to recognize volatile +;; references where it's safe. +(define_predicate "volatile_mem_operand" + (and (match_code "mem") + (match_test "MEM_VOLATILE_P (op)") + (if_then_else (match_test "reload_completed") + (match_operand 0 "memory_operand") + (match_test "memory_address_p (mode, XEXP (op, 0))")))) + +;; Return true if the operand is a register or memory; including volatile +;; memory. +(define_predicate "reg_or_mem_operand" + (ior (match_operand 0 "nonimmediate_operand") + (match_operand 0 "volatile_mem_operand")))
gcc/testsuite/gcc.target/or1k/swap-1.c new file +86 -0
86 lines not on this page · raw message
gcc/testsuite/gcc.target/or1k/swap-2.c new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.19.1
PATCH 1/2 or1k: Fix code quality for volatile memory loads
Quoted 3 lines · Stafford Horne
Volatile memory does not match the
memory_operandpredicate. This causes extra extend/mask instructions instructions when reading from volatile memory. On OpenRISC loading volitile memory can be
s/volitile/volatile/g
also at least in the test.
Thanks,
Quoted 8 lines
gcc/testsuite/gcc.target/or1k/swap-2.c new file +1
-0+/* Check to ensure the volitile load does not get zero extended. */
PATCH 1/2 or1k: Fix code quality for volatile memory loads
Quoted 9 lines · Bernhard Reutner-Fischer
Quoted 3 lines · Stafford Horne
Volatile memory does not match the
memory_operandpredicate. This causes extra extend/mask instructions instructions when reading from volatile memory. On OpenRISC loading volitile memory can bes/volitile/volatile/g
also at least in the test.
Thanks,
Thank you,
I always mispell that one.
-Stafford
Quoted 10 lines
Quoted 9 lines
gcc/testsuite/gcc.target/or1k/swap-2.c new file +1
-0+/* Check to ensure the volitile load does not get zero extended. */
PATCH 2/2 or1k: Fix issues with msoft-div
In reply to Stafford HorneAs reported by Richard Selvaggi. Also, add a basic test to verify the soft math works when enabled.
gcc/testsuite/ChangeLog:
PR target/90362 * gcc.target/or1k/div-mul-3.c: New test.
libgcc/ChangeLog:
PR target/90362
* config/or1k/lib1funcs.S (__udivsi3): Change l.sfeqi to l.sfeq and l.sfltsi to l.sflts equivalents as the immediate instructions are not available on every processor. Change a l.bnf to l.bf to fix logic issue.
--- gcc/testsuite/gcc.target/or1k/div-mul-3.c | 31 +++++++++++++++++++++++ libgcc/config/or1k/lib1funcs.S | 6 ++--- 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/or1k/div-mul-3.c
gcc/testsuite/gcc.target/or1k/div-mul-3.c new file +31 -0
@@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -msoft-div -msoft-mul" } */ + +struct testcase { +int a; +int b; +int c; +int expected; +}; + +struct testcase tests[] = { + {2 ,200 ,3 ,133 }, + {3 ,300 ,3 ,300 }, + {2 ,500 ,3 ,333 }, + {4 ,250 ,3 ,333 }, + {0 ,0 ,0 ,0 } +}; + +int calc (int a,int b,int c) { +return a * b / c; +} + +int main () { +int fail =0 ; +struct testcase *tc; + +for (int i =0 ; (tc = &tests[i], tc->c); i++) + fail |= (calc (tc->a, tc->b, tc->c) != tc->expected); + +return fail; +}
libgcc/config/or1k/lib1funcs.S +3 -3
@@ -68,18 +68,18 @@ __udivmodsi3_internal: is not clobbered by this routine, and use that as to save a return address without creating a stack frame. */ - l.sfeqi r4, 0 /* division by zero; return 0. */ + l.sfeq r4, r0 /* division by zero; return 0. */ l.ori r11, r0, 0 /* initial quotient */ l.bf 9f l.ori r12, r3, 0 /* initial remainder */ /* Given X/Y, shift Y left until Y >= X. */ l.ori r6, r0, 1 /* mask = 1 */ -1: l.sfltsi r4, 0 /* y has msb set */ +1: l.sflts r4, r0 /* y has msb set */ l.bf 2f l.sfltu r4, r12 /* y < x */ l.add r4, r4, r4 /* y <<= 1 */ - l.bnf 1b + l.bf 1b l.add r6, r6, r6 /* mask <<= 1 */ /* Shift Y back to the right again, subtracting from X. */
Signature · 1 line
2.19.1