[llvm-commits] [llvm] r122414 - in /llvm/trunk: lib/Analysis/InstructionSimplify.cpp test/Transforms/InstSimplify/2010-12-20-Distribute.ll
Duncan Sands
baldrick at free.fr
Wed Dec 22 09:15:26 PST 2010
Author: baldrick
Date: Wed Dec 22 11:15:25 2010
New Revision: 122414
URL: http://llvm.org/viewvc/llvm-project?rev=122414&view=rev
Log:
When determining whether the new instruction was already present in
the original instruction, half the cases were missed (making it not
wrong but suboptimal). Also correct a typo (A <-> B) in the second
chunk.
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/test/Transforms/InstSimplify/2010-12-20-Distribute.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=122414&r1=122413&r2=122414&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Wed Dec 22 11:15:25 2010
@@ -159,10 +159,11 @@
// Does "B op DD" simplify?
if (Value *V = SimplifyBinOp(Opcode, B, DD, TD, DT, MaxRecurse)) {
// It does! Return "A op' V" if it simplifies or is already available.
- // If V equals B then "A op' V" is just the LHS.
- if (V == B) {
+ // If V equals B then "A op' V" is just the LHS. If V equals DD then
+ // "A op' V" is just the RHS.
+ if (V == B || V == DD) {
++NumFactor;
- return LHS;
+ return V == B ? LHS : RHS;
}
// Otherwise return "A op' V" if it simplifies.
if (Value *W = SimplifyBinOp(OpcodeToExtract, A, V, TD, DT, MaxRecurse)) {
@@ -181,10 +182,11 @@
// Does "A op CC" simplify?
if (Value *V = SimplifyBinOp(Opcode, A, CC, TD, DT, MaxRecurse)) {
// It does! Return "V op' B" if it simplifies or is already available.
- // If V equals A then "V op' B" is just the LHS.
- if (V == B) {
+ // If V equals A then "V op' B" is just the LHS. If V equals CC then
+ // "V op' B" is just the RHS.
+ if (V == A || V == CC) {
++NumFactor;
- return LHS;
+ return V == A ? LHS : RHS;
}
// Otherwise return "V op' B" if it simplifies.
if (Value *W = SimplifyBinOp(OpcodeToExtract, V, B, TD, DT, MaxRecurse)) {
Modified: llvm/trunk/test/Transforms/InstSimplify/2010-12-20-Distribute.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/2010-12-20-Distribute.ll?rev=122414&r1=122413&r2=122414&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/2010-12-20-Distribute.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/2010-12-20-Distribute.ll Wed Dec 22 11:15:25 2010
@@ -20,6 +20,17 @@
; CHECK: ret i32 %x
}
+define i32 @factorize3(i32 %x, i32 %a, i32 %b) {
+; CHECK: @factorize3
+; (X | (A|B)) & (X | B) -> X | ((A|B) & B) -> X | B
+ %aORb = or i32 %a, %b
+ %l = or i32 %x, %aORb
+ %r = or i32 %x, %b
+ %z = and i32 %l, %r
+ ret i32 %z
+; CHECK: ret i32 %r
+}
+
define i32 @expand(i32 %x) {
; CHECK: @expand
; ((X & 1) | 2) & 1 -> ((X & 1) & 1) | (2 & 1) -> (X & 1) | 0 -> X & 1
More information about the llvm-commits
mailing list