[llvm-commits] [llvm] r58351 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/logical-select.ll
Dan Gohman
gohman at apple.com
Tue Oct 28 15:39:03 PDT 2008
Author: djg
Date: Tue Oct 28 17:38:57 2008
New Revision: 58351
URL: http://llvm.org/viewvc/llvm-project?rev=58351&view=rev
Log:
(A & sext(C)) | (B & ~sext(C) -> C ? A : B
Added:
llvm/trunk/test/Transforms/InstCombine/logical-select.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=58351&r1=58350&r2=58351&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Tue Oct 28 17:38:57 2008
@@ -4337,6 +4337,25 @@
return BinaryOperator::CreateAnd(V1, Or);
}
}
+
+ // (A & sext(C0)) | (B & ~sext(C0) -> C0 ? A : B
+ if (isa<SExtInst>(C) &&
+ cast<User>(C)->getOperand(0)->getType() == Type::Int1Ty) {
+ if (match(D, m_Not(m_Value(C))))
+ return SelectInst::Create(cast<User>(C)->getOperand(0), A, B);
+ // And commutes, try both ways.
+ if (match(B, m_Not(m_Value(C))))
+ return SelectInst::Create(cast<User>(C)->getOperand(0), A, D);
+ }
+ // Or commutes, try both ways.
+ if (isa<SExtInst>(D) &&
+ cast<User>(D)->getOperand(0)->getType() == Type::Int1Ty) {
+ if (match(C, m_Not(m_Value(D))))
+ return SelectInst::Create(cast<User>(D)->getOperand(0), A, B);
+ // And commutes, try both ways.
+ if (match(A, m_Not(m_Value(D))))
+ return SelectInst::Create(cast<User>(D)->getOperand(0), C, B);
+ }
}
// (X >> Z) | (Y >> Z) -> (X|Y) >> Z for all shifts.
Added: llvm/trunk/test/Transforms/InstCombine/logical-select.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/logical-select.ll?rev=58351&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/logical-select.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/logical-select.ll Tue Oct 28 17:38:57 2008
@@ -0,0 +1,20 @@
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep select | count 2
+
+define i32 @foo(i32 %a, i32 %b, i32 %c, i32 %d) nounwind {
+ %e = icmp slt i32 %a, %b
+ %f = sext i1 %e to i32
+ %g = and i32 %c, %f
+ %h = xor i32 %f, -1
+ %i = and i32 %d, %h
+ %j = or i32 %g, %i
+ ret i32 %j
+}
+define i32 @bar(i32 %a, i32 %b, i32 %c, i32 %d) nounwind {
+ %e = icmp slt i32 %a, %b
+ %f = sext i1 %e to i32
+ %g = and i32 %c, %f
+ %h = xor i32 %f, -1
+ %i = and i32 %d, %h
+ %j = or i32 %i, %g
+ ret i32 %j
+}
More information about the llvm-commits
mailing list