arc: Use separate predicated patterns for mpyd(u)
authorClaudiu Zissulescu <claziss@gmail.com>
Tue, 28 Jul 2020 10:15:48 +0000 (13:15 +0300)
committerClaudiu Zissulescu <claziss@synopsys.com>
Fri, 11 Dec 2020 16:13:53 +0000 (18:13 +0200)
The compiler can match mpyd.eq r0,r1,r0 as a predicated instruction,
which is incorrect. The mpyd(u) instruction takes as input two 32-bit
registers, returning into a double 64-bit even-odd register pair.  For
the predicated case, the ARC instruction decoder expects the
destination register to be the same as the first input register. In
the big-endian case the result is swaped in the destination register
pair, however, the instruction encoding remains the same.  Refurbish
the mpyd(u) patterns to take into account the above observation.

gcc/
2020-12-11  Claudiu Zissulescu  <claziss@synopsys.com>

* config/arc/arc.md (mpyd<su_optab>_arcv2hs): New template
pattern.
(*pmpyd<su_optab>_arcv2hs): Likewise.
(*pmpyd<su_optab>_imm_arcv2hs): Likewise.
(mpyd_arcv2hs): Moved into above template.
(mpyd_imm_arcv2hs): Moved into above template.
(mpydu_arcv2hs): Likewise.
(mpydu_imm_arcv2hs): Likewise.
(su_optab): New optab prefix for sign/zero-extending operations.

gcc/testsuite/
2020-12-11  Claudiu Zissulescu  <claziss@synopsys.com>

* gcc.target/arc/pmpyd.c: New test.
* gcc.target/arc/tmac-1.c: Update.

Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
gcc/config/arc/arc.md
gcc/testsuite/gcc.target/arc/pmpyd.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arc/tmac-1.c

index 266b7ce7666cf39b28e9aa9b27ee0c8ddeeac036..2b46e26553861ea6f4a1f1de32460e3d64f256f4 100644 (file)
@@ -871,6 +871,8 @@ core_3, archs4x, archs4xd, archs4xd_slow"
 
 (define_code_iterator SEZ [sign_extend zero_extend])
 (define_code_attr SEZ_prefix [(sign_extend "sex") (zero_extend "ext")])
+; Optab prefix for sign/zero-extending operations
+(define_code_attr su_optab [(sign_extend "") (zero_extend "u")])
 
 (define_insn "*<SEZ_prefix>xt<SQH_postfix>_cmp0_noout"
   [(set (match_operand 0 "cc_set_register" "")
@@ -6385,66 +6387,65 @@ core_3, archs4x, archs4xd, archs4xd_slow"
    (set_attr "predicable" "no")
    (set_attr "cond" "nocond")])
 
-(define_insn "mpyd_arcv2hs"
-  [(set (match_operand:DI 0 "even_register_operand"                    "=Rcr, r")
-       (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand"  "  0, c"))
-                (sign_extend:DI (match_operand:SI 2 "register_operand"  "  c, c"))))
+(define_insn "mpyd<su_optab>_arcv2hs"
+  [(set (match_operand:DI 0 "even_register_operand"           "=r")
+       (mult:DI (SEZ:DI (match_operand:SI 1 "register_operand" "r"))
+                (SEZ:DI (match_operand:SI 2 "register_operand" "r"))))
    (set (reg:DI ARCV2_ACC)
        (mult:DI
-         (sign_extend:DI (match_dup 1))
-         (sign_extend:DI (match_dup 2))))]
+         (SEZ:DI (match_dup 1))
+         (SEZ:DI (match_dup 2))))]
   "TARGET_PLUS_MACD"
-  "mpyd%? %0,%1,%2"
-  [(set_attr "length" "4,4")
-  (set_attr "iscompact" "false")
-  (set_attr "type" "multi")
-  (set_attr "predicable" "yes,no")
-  (set_attr "cond" "canuse,nocond")])
-
-(define_insn "mpyd_imm_arcv2hs"
-  [(set (match_operand:DI 0 "even_register_operand"                    "=Rcr, r,r,Rcr,  r")
-       (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand"  "  0, c,0,  0,  c"))
-                (match_operand 2                   "immediate_operand"  "  L, L,I,Cal,Cal")))
+  "mpyd<su_optab>%?\\t%0,%1,%2"
+  [(set_attr "length" "4")
+   (set_attr "iscompact" "false")
+   (set_attr "type" "multi")
+   (set_attr "predicable" "no")])
+
+(define_insn "*pmpyd<su_optab>_arcv2hs"
+  [(set (match_operand:DI 0 "even_register_operand"         "=r")
+       (mult:DI
+        (SEZ:DI (match_operand:SI 1 "even_register_operand" "%0"))
+        (SEZ:DI (match_operand:SI 2 "register_operand"      "r"))))
    (set (reg:DI ARCV2_ACC)
-       (mult:DI (sign_extend:DI (match_dup 1))
-                (match_dup 2)))]
+       (mult:DI
+         (SEZ:DI (match_dup 1))
+         (SEZ:DI (match_dup 2))))]
   "TARGET_PLUS_MACD"
-  "mpyd%? %0,%1,%2"
-  [(set_attr "length" "4,4,4,8,8")
-  (set_attr "iscompact" "false")
-  (set_attr "type" "multi")
-  (set_attr "predicable" "yes,no,no,yes,no")
-  (set_attr "cond" "canuse,nocond,nocond,canuse_limm,nocond")])
-
-(define_insn "mpydu_arcv2hs"
-  [(set (match_operand:DI 0 "even_register_operand"                    "=Rcr, r")
-       (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand"  "  0, c"))
-                (zero_extend:DI (match_operand:SI 2 "register_operand" "   c, c"))))
+  "mpyd<su_optab>%?\\t%0,%1,%2"
+  [(set_attr "length" "4")
+   (set_attr "iscompact" "false")
+   (set_attr "type" "multi")
+   (set_attr "predicable" "yes")])
+
+(define_insn "mpyd<su_optab>_imm_arcv2hs"
+  [(set (match_operand:DI 0 "even_register_operand"            "=r,r,  r")
+       (mult:DI (SEZ:DI (match_operand:SI 1 "register_operand"  "r,0,  r"))
+                (match_operand 2            "immediate_operand" "L,I,Cal")))
    (set (reg:DI ARCV2_ACC)
-       (mult:DI (zero_extend:DI (match_dup 1))
-                (zero_extend:DI (match_dup 2))))]
+       (mult:DI (SEZ:DI (match_dup 1))
+                (match_dup 2)))]
   "TARGET_PLUS_MACD"
-  "mpydu%? %0,%1,%2"
-  [(set_attr "length" "4,4")
-  (set_attr "iscompact" "false")
-  (set_attr "type" "multi")
-  (set_attr "predicable" "yes,no")
-  (set_attr "cond" "canuse,nocond")])
-
-(define_insn "mpydu_imm_arcv2hs"
-  [(set (match_operand:DI 0 "even_register_operand"                    "=Rcr, r,r,Rcr,  r")
-       (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand"  "  0, c,0,  0,  c"))
-                (match_operand 2                   "immediate_operand"  "  L, L,I,Cal,Cal")))
+  "mpyd<su_optab>%?\\t%0,%1,%2"
+  [(set_attr "length" "4,4,8")
+   (set_attr "iscompact" "false")
+   (set_attr "type" "multi")
+   (set_attr "predicable" "no")])
+
+(define_insn "*pmpyd<su_optab>_imm_arcv2hs"
+  [(set (match_operand:DI 0 "even_register_operand"        "=r,r")
+       (mult:DI
+        (SEZ:DI (match_operand:SI 1 "even_register_operand" "0,0"))
+        (match_operand 2            "immediate_operand"     "L,Cal")))
    (set (reg:DI ARCV2_ACC)
-       (mult:DI (zero_extend:DI (match_dup 1))
+       (mult:DI (SEZ:DI (match_dup 1))
                 (match_dup 2)))]
   "TARGET_PLUS_MACD"
-  "mpydu%? %0,%1,%2"
-  [(set_attr "length" "4,4,4,8,8")
-  (set_attr "iscompact" "false")
-  (set_attr "type" "multi")
-  (set_attr "predicable" "yes,no,no,yes,no")
-  (set_attr "cond" "canuse,nocond,nocond,canuse_limm,nocond")])
+  "mpyd<su_optab>%?\\t%0,%1,%2"
+  [(set_attr "length" "4,8")
+   (set_attr "iscompact" "false")
+   (set_attr "type" "multi")
+   (set_attr "predicable" "yes")])
 
 (define_insn "*add_shift"
   [(set (match_operand:SI 0 "register_operand" "=q,r,r")
diff --git a/gcc/testsuite/gcc.target/arc/pmpyd.c b/gcc/testsuite/gcc.target/arc/pmpyd.c
new file mode 100644 (file)
index 0000000..0eb0ff7
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do assemble } */
+/* { dg-skip-if "" { ! { clmcpu } } } */
+/* { dg-options "-mcpu=hs38 -Os -EB" } */
+
+/* This example is found during big-endian build.  The compiler is
+   matching mpydu.hi r12,r13,r3 as a predicated instruction, which is
+   incorrect.  The error is due to different predicates between the
+   output operand and the first operand of the instruction.  */
+unsigned int test(unsigned int x, unsigned long long y)
+{
+  y /= 0x20000000;
+  if (x > 1)
+    y *= x;
+  return y;
+}
index 3fcabf5fff2d6610d410b55cac632d79668497d7..5b302cad4a4a2a69427b6a89a536df46b2b85677 100644 (file)
@@ -7,5 +7,5 @@
 
 /* { dg-final { scan-assembler "macd " } } */
 /* { dg-final { scan-assembler "macdu" } } */
-/* { dg-final { scan-assembler "mpyd " } } */
+/* { dg-final { scan-assembler "mpyd\\t" } } */
 /* { dg-final { scan-assembler "mpydu" } } */