tstellar / rpms / gcc

Forked from rpms/gcc 4 years ago
Clone
0bc6460
2015-02-26  Jakub Jelinek  <jakub@redhat.com>
0bc6460
	    Aldy Hernandez  <aldyh@redhat.com>
0bc6460
0bc6460
	PR rtl-optimization/65220
0bc6460
	* config/i386/i386.md (*udivmod<mode>4_pow2): New.
0bc6460
0bc6460
--- gcc/config/i386/i386.md	(revision 221063)
0bc6460
+++ gcc/config/i386/i386.md	(revision 221064)
0bc6460
@@ -7331,6 +7331,32 @@ (define_insn_and_split "*udivmod<mode>4"
0bc6460
   [(set_attr "type" "multi")
0bc6460
    (set_attr "mode" "<MODE>")])
0bc6460
 
0bc6460
+;; Optimize division or modulo by constant power of 2, if the constant
0bc6460
+;; materializes only after expansion.
0bc6460
+(define_insn_and_split "*udivmod<mode>4_pow2"
0bc6460
+  [(set (match_operand:SWI48 0 "register_operand" "=r")
0bc6460
+	(udiv:SWI48 (match_operand:SWI48 2 "register_operand" "0")
0bc6460
+		    (match_operand:SWI48 3 "const_int_operand" "n")))
0bc6460
+   (set (match_operand:SWI48 1 "register_operand" "=r")
0bc6460
+	(umod:SWI48 (match_dup 2) (match_dup 3)))
0bc6460
+   (clobber (reg:CC FLAGS_REG))]
0bc6460
+  "UINTVAL (operands[3]) - 2 < <MODE_SIZE> * BITS_PER_UNIT
0bc6460
+   && (UINTVAL (operands[3]) & (UINTVAL (operands[3]) - 1)) == 0"
0bc6460
+  "#"
0bc6460
+  "&& reload_completed"
0bc6460
+  [(set (match_dup 1) (match_dup 2))
0bc6460
+   (parallel [(set (match_dup 0) (lshiftrt:<MODE> (match_dup 2) (match_dup 4)))
0bc6460
+	      (clobber (reg:CC FLAGS_REG))])
0bc6460
+   (parallel [(set (match_dup 1) (and:<MODE> (match_dup 1) (match_dup 5)))
0bc6460
+	      (clobber (reg:CC FLAGS_REG))])]
0bc6460
+{
0bc6460
+  int v = exact_log2 (UINTVAL (operands[3]));
0bc6460
+  operands[4] = GEN_INT (v);
0bc6460
+  operands[5] = GEN_INT ((HOST_WIDE_INT_1U << v) - 1);
0bc6460
+}
0bc6460
+  [(set_attr "type" "multi")
0bc6460
+   (set_attr "mode" "<MODE>")])
0bc6460
+
0bc6460
 (define_insn "*udivmod<mode>4_noext"
0bc6460
   [(set (match_operand:SWIM248 0 "register_operand" "=a")
0bc6460
 	(udiv:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
0bc6460
--- gcc/testsuite/gcc.target/i386/pr65520.c	(revision 0)
0bc6460
+++ gcc/testsuite/gcc.target/i386/pr65520.c	(revision 221064)
0bc6460
@@ -0,0 +1,20 @@
0bc6460
+/* PR target/65520 */
0bc6460
+/* { dg-do compile } */
0bc6460
+/* { dg-options "-O2" } */
0bc6460
+
0bc6460
+int foo (void *);
0bc6460
+
0bc6460
+void
0bc6460
+bar (void)
0bc6460
+{
0bc6460
+  unsigned s = 128;
0bc6460
+  while (1)
0bc6460
+    {
0bc6460
+      unsigned b[s];
0bc6460
+      if (foo (b))
0bc6460
+	break;
0bc6460
+      s *= 2;
0bc6460
+    }
0bc6460
+}
0bc6460
+
0bc6460
+/* { dg-final { scan-assembler-not "div\[^\n\r]*%" } } */