[llvm-commits] [llvm] r129545 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp test/Transforms/InstCombine/or.ll
Eli Friedman
eli.friedman at gmail.com
Thu Apr 14 15:41:27 PDT 2011
Author: efriedma
Date: Thu Apr 14 17:41:27 2011
New Revision: 129545
URL: http://llvm.org/viewvc/llvm-project?rev=129545&view=rev
Log:
Add an instcombine for constructs like a | -(b != c); a select is more
canonical, and generally leads to better code. Found while looking at
an article about saturating arithmetic.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/trunk/test/Transforms/InstCombine/or.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=129545&r1=129544&r2=129545&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Thu Apr 14 17:41:27 2011
@@ -2003,7 +2003,14 @@
}
}
}
-
+
+ // or(sext(A), B) -> A ? -1 : B where A is an i1
+ // or(A, sext(B)) -> B ? -1 : A where B is an i1
+ if (match(Op0, m_SExt(m_Value(A))) && A->getType()->isIntegerTy(1))
+ return SelectInst::Create(A, ConstantInt::getSigned(I.getType(), -1), Op1);
+ if (match(Op1, m_SExt(m_Value(A))) && A->getType()->isIntegerTy(1))
+ return SelectInst::Create(A, ConstantInt::getSigned(I.getType(), -1), Op0);
+
// Note: If we've gotten to the point of visiting the outer OR, then the
// inner one couldn't be simplified. If it was a constant, then it won't
// be simplified by a later pass either, so we try swapping the inner/outer
Modified: llvm/trunk/test/Transforms/InstCombine/or.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/or.ll?rev=129545&r1=129544&r2=129545&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/or.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/or.ll Thu Apr 14 17:41:27 2011
@@ -390,3 +390,22 @@
; CHECK-NEXT: ret i1
}
+define i32 @test37(i32* %xp, i32 %y) {
+; CHECK: @test37
+; CHECK: select i1 %tobool, i32 -1, i32 %x
+ %tobool = icmp ne i32 %y, 0
+ %sext = sext i1 %tobool to i32
+ %x = load i32* %xp
+ %or = or i32 %sext, %x
+ ret i32 %or
+}
+
+define i32 @test38(i32* %xp, i32 %y) {
+; CHECK: @test38
+; CHECK: select i1 %tobool, i32 -1, i32 %x
+ %tobool = icmp ne i32 %y, 0
+ %sext = sext i1 %tobool to i32
+ %x = load i32* %xp
+ %or = or i32 %x, %sext
+ ret i32 %or
+}
More information about the llvm-commits
mailing list