[llvm-commits] [llvm] r130238 - in /llvm/trunk: lib/Target/README.txt lib/Transforms/InstCombine/InstCombineCompares.cpp test/Transforms/InstCombine/icmp.ll
Chris Lattner
sabre at nondot.org
Tue Apr 26 13:18:20 PDT 2011
Author: lattner
Date: Tue Apr 26 15:18:20 2011
New Revision: 130238
URL: http://llvm.org/viewvc/llvm-project?rev=130238&view=rev
Log:
Transform: "icmp eq (trunc (lshr(X, cst1)), cst" to "icmp (and X, mask), cst"
when X has multiple uses. This is useful for exposing secondary optimizations,
but the X86 backend isn't ready for this when X has a single use. For example,
this can disable load folding.
This is inching towards resolving PR6627.
Modified:
llvm/trunk/lib/Target/README.txt
llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/trunk/test/Transforms/InstCombine/icmp.ll
Modified: llvm/trunk/lib/Target/README.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/README.txt?rev=130238&r1=130237&r2=130238&view=diff
==============================================================================
--- llvm/trunk/lib/Target/README.txt (original)
+++ llvm/trunk/lib/Target/README.txt Tue Apr 26 15:18:20 2011
@@ -2259,52 +2259,6 @@
//===---------------------------------------------------------------------===//
-We should optimize this:
-
- %tmp = load i16* %arrayidx, align 4, !tbaa !0
- %A = trunc i16 %tmp to i8
- %cmp = icmp eq i8 %A, 127
- %B.mask = and i16 %tmp, -256
- %cmp7 = icmp eq i16 %B.mask, 17664
- %or.cond = and i1 %cmp, %cmp7
- br i1 %or.cond, label %land.lhs.true9, label %if.end
-
-into:
-
- %tmp = load i16* %arrayidx, align 4, !tbaa !0
- %0 = icmp eq i16 %tmp, 17791
- br i1 %0, label %land.lhs.true9, label %if.end
-
-with this patch:
-Index: InstCombine/InstCombineCompares.cpp
-===================================================================
---- InstCombine/InstCombineCompares.cpp (revision 129500)
-+++ InstCombine/InstCombineCompares.cpp (working copy)
-@@ -2506,6 +2506,18 @@
- return &I;
- }
- }
-+
-+ // Transform "icmp eq (trunc X), cst" to "icmp (and X, mask), cst"
-+ if (Op0->hasOneUse() && match(Op0, m_Trunc(m_Value(A))) &&
-+ isa<ConstantInt>(Op1)) {
-+ APInt MaskV = APInt::getLowBitsSet(A->getType()->getPrimitiveSizeInBits(),
-+ Op0->getType()->getPrimitiveSizeInBits());
-+ Value *Mask =
-+ Builder->CreateAnd(A, ConstantInt::get(A->getContext(), MaskV));
-+ return new ICmpInst(I.getPredicate(), Mask,
-+ ConstantExpr::getZExt(cast<ConstantInt>(Op1),
-+ Mask->getType()));
-+ }
- }
-
- {
-
-
-Not having this is blocking resolving PR6627.
-
-//===---------------------------------------------------------------------===//
-
This code:
typedef struct {
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=130238&r1=130237&r2=130238&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Tue Apr 26 15:18:20 2011
@@ -2506,6 +2506,31 @@
}
}
+ // Transform "icmp eq (trunc (lshr(X, cst1)), cst" to
+ // "icmp (and X, mask), cst"
+ uint64_t ShAmt = 0;
+ ConstantInt *Cst1;
+ if (Op0->hasOneUse() &&
+ match(Op0, m_Trunc(m_OneUse(m_LShr(m_Value(A),
+ m_ConstantInt(ShAmt))))) &&
+ match(Op1, m_ConstantInt(Cst1)) &&
+ // Only do this when A has multiple uses. This is most important to do
+ // when it exposes other optimizations.
+ !A->hasOneUse()) {
+ unsigned ASize =cast<IntegerType>(A->getType())->getPrimitiveSizeInBits();
+
+ if (ShAmt < ASize) {
+ APInt MaskV =
+ APInt::getLowBitsSet(ASize, Op0->getType()->getPrimitiveSizeInBits());
+ MaskV <<= ShAmt;
+
+ APInt CmpV = Cst1->getValue().zext(ASize);
+ CmpV <<= ShAmt;
+
+ Value *Mask = Builder->CreateAnd(A, Builder->getInt(MaskV));
+ return new ICmpInst(I.getPredicate(), Mask, Builder->getInt(CmpV));
+ }
+ }
}
{
Modified: llvm/trunk/test/Transforms/InstCombine/icmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp.ll?rev=130238&r1=130237&r2=130238&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/icmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/icmp.ll Tue Apr 26 15:18:20 2011
@@ -494,3 +494,19 @@
%C = icmp sgt i32 %B, -1
ret i1 %C
}
+
+; CHECK: @test52
+; CHECK-NEXT: and i32 %x1, 16711935
+; CHECK-NEXT: icmp eq i32 {{.*}}, 4980863
+; CHECK-NEXT: ret i1
+define i1 @test52(i32 %x1) nounwind {
+ %conv = and i32 %x1, 255
+ %cmp = icmp eq i32 %conv, 127
+ %tmp2 = lshr i32 %x1, 16
+ %tmp3 = trunc i32 %tmp2 to i8
+ %cmp15 = icmp eq i8 %tmp3, 76
+
+ %A = and i1 %cmp, %cmp15
+ ret i1 %A
+}
+
More information about the llvm-commits
mailing list