This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix invalid cc_status after [const_][us]mulsi3_highpart


The mulu.l insn sets the CC according to the 64-bit result, but we are
only using the high part, so the Z flag cannot be used.  The other flags
would still be valid, but we have no cc_status flag for that case.

	* config/m68k/m68k.md (umulsi3_highpart+1, const_umulsi3_highpart)
	(smulsi3_highpart+1, const_smulsi3_highpart): Add CC_STATUS_INIT.

testsuite/:
	* gcc.target/m68k/mulsi_highpart.c: New test.

diff --git a/gcc/config/m68k/m68k.md b/gcc/config/m68k/m68k.md
index f8a674d7d9..74c366fc63 100644
--- a/gcc/config/m68k/m68k.md
+++ b/gcc/config/m68k/m68k.md
@@ -3240,7 +3240,10 @@
 	  (const_int 32))))
    (clobber (match_operand:SI 1 "register_operand" "=d"))]
   "TARGET_68020 && !TUNE_68060 && !TARGET_COLDFIRE"
-  "mulu%.l %3,%0:%1")
+{
+  CC_STATUS_INIT;
+  return "mulu%.l %3,%0:%1";
+})
 
 (define_insn "const_umulsi3_highpart"
   [(set (match_operand:SI 0 "register_operand" "=d")
@@ -3251,7 +3254,10 @@
 	  (const_int 32))))
    (clobber (match_operand:SI 1 "register_operand" "=d"))]
   "TARGET_68020 && !TUNE_68060 && !TARGET_COLDFIRE"
-  "mulu%.l %3,%0:%1")
+{
+  CC_STATUS_INIT;
+  return "mulu%.l %3,%0:%1";
+})
 
 (define_expand "smulsi3_highpart"
   [(parallel
@@ -3283,7 +3289,10 @@
 	  (const_int 32))))
    (clobber (match_operand:SI 1 "register_operand" "=d"))]
   "TARGET_68020 && !TUNE_68060 && !TARGET_COLDFIRE"
-  "muls%.l %3,%0:%1")
+{
+  CC_STATUS_INIT;
+  return "muls%.l %3,%0:%1";
+})
 
 (define_insn "const_smulsi3_highpart"
   [(set (match_operand:SI 0 "register_operand" "=d")
@@ -3294,7 +3303,10 @@
 	  (const_int 32))))
    (clobber (match_operand:SI 1 "register_operand" "=d"))]
   "TARGET_68020 && !TUNE_68060 && !TARGET_COLDFIRE"
-  "muls%.l %3,%0:%1")
+{
+  CC_STATUS_INIT;
+  return "muls%.l %3,%0:%1";
+})
 
 (define_expand "mul<mode>3"
   [(set (match_operand:FP 0 "nonimmediate_operand" "")
diff --git a/gcc/testsuite/gcc.target/m68k/mulsi_highpart.c b/gcc/testsuite/gcc.target/m68k/mulsi_highpart.c
new file mode 100644
index 0000000000..f17586ee52
--- /dev/null
+++ b/gcc/testsuite/gcc.target/m68k/mulsi_highpart.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -m68020" } */
+/* Don't optimize away a compare after [us]mulsi_highpart.  */
+/* { dg-final { scan-assembler {tst\.?l} } } */
+int cmp (unsigned int a, unsigned int b)
+{
+  return (a > 0xffffffff / b);
+}
-- 
2.18.0


-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]