This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] for PR18942
- From: Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 19 Dec 2004 10:56:19 +0100
- Subject: [patch] for PR18942
Hello,
in the testcase of the PR:
int ivtmp51;
int D1360 = n/2;
x = D1360 - 1
ivtmp51 = 1;
do {
ivtmp51++;
} while (x > ivtmp51);
We get the following condition for the loop
not to roll:
D1360 - 1 < 2 || D1360 - 1 == MIN_INT
Which gets emitted to code during doloop optimizations. However
obviously the condition is equivalent just to D1360 - 1 < 2,
since D1360 - 1 == MIN_INT implies D1360 - 1 < 2. # of iterations
already tries to eliminate conditions this way, but rtl simplification
is not powerful enough to find out that this can be done in this case.
However after teaching it to replace D1360 - 1 == MIN_INT by
D1360 == MIN_INT + 1, everything works.
Bootstrapped & regtested on ppc.
Zdenek
PR rtl-optimization/18942
* simplify-rtx.c (simplify_relational_operation_1): Simplify
x + cst1 == cst2 to x == cst2 - cst1.
Index: simplify-rtx.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/simplify-rtx.c,v
retrieving revision 1.216
diff -c -3 -p -r1.216 simplify-rtx.c
*** simplify-rtx.c 16 Dec 2004 19:16:54 -0000 1.216
--- simplify-rtx.c 18 Dec 2004 22:46:40 -0000
*************** simplify_relational_operation_1 (enum rt
*** 2800,2805 ****
--- 2800,2821 ----
}
}
+ /* (eq/ne (plus x cst1) cst2) simplifies to (eq/ne x (cst2 - cst1)) */
+ if ((code == EQ || code == NE)
+ && CONSTANT_P (op1)
+ && GET_CODE (op0) == PLUS)
+ {
+ rtx x = XEXP (op0, 0);
+ rtx c = XEXP (op0, 1);
+
+ if (CONSTANT_P (c))
+ {
+ c = simplify_gen_binary (MINUS, cmp_mode, op1, c);
+
+ return simplify_gen_relational (code, mode, cmp_mode, x, c);
+ }
+ }
+
return NULL_RTX;
}