|
| 1 | +From 06ff8708f0b834cf1b35afa46113c6c973905cad Mon Sep 17 00:00:00 2001 |
| 2 | +From: Max Filippov <jcmvbkbc@gmail.com> |
| 3 | +Date: Sat, 12 Dec 2020 12:14:40 -0800 |
| 4 | +Subject: [PATCH] gcc: xtensa: fix PR target/98285 |
| 5 | + |
| 6 | +2020-12-14 Max Filippov <jcmvbkbc@gmail.com> |
| 7 | +gcc/ |
| 8 | + * config/xtensa/predicates.md (addsubx_operand): Change accepted |
| 9 | + values from 2/4/8 to 1..3. |
| 10 | + * config/xtensa/xtensa.md (*addx, *subx): Change RTL pattern |
| 11 | + to use 'ashift' instead of 'mult'. Update operands[3] value. |
| 12 | + |
| 13 | +gcc/testsuite/ |
| 14 | + * gcc.target/xtensa/pr98285.c: New test. |
| 15 | +--- |
| 16 | + gcc/config/xtensa/predicates.md | 5 +-- |
| 17 | + gcc/config/xtensa/xtensa.md | 18 +++++--- |
| 18 | + gcc/testsuite/gcc.target/xtensa/pr98285.c | 54 +++++++++++++++++++++++ |
| 19 | + 3 files changed, 68 insertions(+), 9 deletions(-) |
| 20 | + create mode 100644 gcc/testsuite/gcc.target/xtensa/pr98285.c |
| 21 | + |
| 22 | +diff --git a/gcc/config/xtensa/predicates.md b/gcc/config/xtensa/predicates.md |
| 23 | +index 1721640dc79e..eb52b05aafad 100644 |
| 24 | +--- a/gcc/config/xtensa/predicates.md |
| 25 | ++++ b/gcc/config/xtensa/predicates.md |
| 26 | +@@ -25,9 +25,8 @@ |
| 27 | + |
| 28 | + (define_predicate "addsubx_operand" |
| 29 | + (and (match_code "const_int") |
| 30 | +- (match_test "INTVAL (op) == 2 |
| 31 | +- || INTVAL (op) == 4 |
| 32 | +- || INTVAL (op) == 8"))) |
| 33 | ++ (match_test "INTVAL (op) >= 1 |
| 34 | ++ && INTVAL (op) <= 3"))) |
| 35 | + |
| 36 | + (define_predicate "arith_operand" |
| 37 | + (ior (and (match_code "const_int") |
| 38 | +diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md |
| 39 | +index 749fe477d562..671c4bea144f 100644 |
| 40 | +--- a/gcc/config/xtensa/xtensa.md |
| 41 | ++++ b/gcc/config/xtensa/xtensa.md |
| 42 | +@@ -162,11 +162,14 @@ |
| 43 | + |
| 44 | + (define_insn "*addx" |
| 45 | + [(set (match_operand:SI 0 "register_operand" "=a") |
| 46 | +- (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "r") |
| 47 | +- (match_operand:SI 3 "addsubx_operand" "i")) |
| 48 | ++ (plus:SI (ashift:SI (match_operand:SI 1 "register_operand" "r") |
| 49 | ++ (match_operand:SI 3 "addsubx_operand" "i")) |
| 50 | + (match_operand:SI 2 "register_operand" "r")))] |
| 51 | + "TARGET_ADDX" |
| 52 | +- "addx%3\t%0, %1, %2" |
| 53 | ++{ |
| 54 | ++ operands[3] = GEN_INT (1 << INTVAL (operands[3])); |
| 55 | ++ return "addx%3\t%0, %1, %2"; |
| 56 | ++} |
| 57 | + [(set_attr "type" "arith") |
| 58 | + (set_attr "mode" "SI") |
| 59 | + (set_attr "length" "3")]) |
| 60 | +@@ -196,11 +199,14 @@ |
| 61 | + |
| 62 | + (define_insn "*subx" |
| 63 | + [(set (match_operand:SI 0 "register_operand" "=a") |
| 64 | +- (minus:SI (mult:SI (match_operand:SI 1 "register_operand" "r") |
| 65 | +- (match_operand:SI 3 "addsubx_operand" "i")) |
| 66 | ++ (minus:SI (ashift:SI (match_operand:SI 1 "register_operand" "r") |
| 67 | ++ (match_operand:SI 3 "addsubx_operand" "i")) |
| 68 | + (match_operand:SI 2 "register_operand" "r")))] |
| 69 | + "TARGET_ADDX" |
| 70 | +- "subx%3\t%0, %1, %2" |
| 71 | ++{ |
| 72 | ++ operands[3] = GEN_INT (1 << INTVAL (operands[3])); |
| 73 | ++ return "subx%3\t%0, %1, %2"; |
| 74 | ++} |
| 75 | + [(set_attr "type" "arith") |
| 76 | + (set_attr "mode" "SI") |
| 77 | + (set_attr "length" "3")]) |
| 78 | +diff --git a/gcc/testsuite/gcc.target/xtensa/pr98285.c b/gcc/testsuite/gcc.target/xtensa/pr98285.c |
| 79 | +new file mode 100644 |
| 80 | +index 000000000000..2c037d546565 |
| 81 | +--- /dev/null |
| 82 | ++++ b/gcc/testsuite/gcc.target/xtensa/pr98285.c |
| 83 | +@@ -0,0 +1,54 @@ |
| 84 | ++/* { dg-do compile } */ |
| 85 | ++/* { dg-options "-O2" } */ |
| 86 | ++ |
| 87 | ++int mul3(int v) |
| 88 | ++{ |
| 89 | ++ return v * 3; |
| 90 | ++} |
| 91 | ++ |
| 92 | ++int mul5(int v) |
| 93 | ++{ |
| 94 | ++ return v * 5; |
| 95 | ++} |
| 96 | ++ |
| 97 | ++int mul7(int v) |
| 98 | ++{ |
| 99 | ++ return v * 7; |
| 100 | ++} |
| 101 | ++ |
| 102 | ++int mul9(int v) |
| 103 | ++{ |
| 104 | ++ return v * 9; |
| 105 | ++} |
| 106 | ++ |
| 107 | ++int mul2sub(int a, int b) |
| 108 | ++{ |
| 109 | ++ return a * 2 - b; |
| 110 | ++} |
| 111 | ++ |
| 112 | ++int mul4sub(int a, int b) |
| 113 | ++{ |
| 114 | ++ return a * 4 - b; |
| 115 | ++} |
| 116 | ++ |
| 117 | ++short index2(short *p, int i) |
| 118 | ++{ |
| 119 | ++ return p[i]; |
| 120 | ++} |
| 121 | ++ |
| 122 | ++int index4(int *p, int i) |
| 123 | ++{ |
| 124 | ++ return p[i]; |
| 125 | ++} |
| 126 | ++ |
| 127 | ++long long index8(long long *p, int i) |
| 128 | ++{ |
| 129 | ++ return p[i]; |
| 130 | ++} |
| 131 | ++ |
| 132 | ++/* { dg-final { scan-assembler-times "addx2" 2 } } */ |
| 133 | ++/* { dg-final { scan-assembler-times "addx4" 2 } } */ |
| 134 | ++/* { dg-final { scan-assembler-times "addx8" 2 } } */ |
| 135 | ++/* { dg-final { scan-assembler-times "subx2" 1 } } */ |
| 136 | ++/* { dg-final { scan-assembler-times "subx4" 1 } } */ |
| 137 | ++/* { dg-final { scan-assembler-times "subx8" 1 } } */ |
0 commit comments