[llvm-commits] [llvm] r82386 - in /llvm/trunk: lib/VMCore/ConstantFold.cpp test/Transforms/ConstProp/2009-09-19-ConstFold-i1-ConstExpr.ll
Nick Lewycky
nicholas at mxc.ca
Sun Sep 20 00:21:39 PDT 2009
Author: nicholas
Date: Sun Sep 20 02:21:39 2009
New Revision: 82386
URL: http://llvm.org/viewvc/llvm-project?rev=82386&view=rev
Log:
Fold 'icmp eq (icmp), true' into an xor(icmp).
Modified:
llvm/trunk/lib/VMCore/ConstantFold.cpp
llvm/trunk/test/Transforms/ConstProp/2009-09-19-ConstFold-i1-ConstExpr.ll
Modified: llvm/trunk/lib/VMCore/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ConstantFold.cpp?rev=82386&r1=82385&r2=82386&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/ConstantFold.cpp (original)
+++ llvm/trunk/lib/VMCore/ConstantFold.cpp Sun Sep 20 02:21:39 2009
@@ -1428,6 +1428,20 @@
}
}
+ // If the comparison is a comparison between two i1's, simplify it.
+ if (C1->getType() == Type::getInt1Ty(Context)) {
+ switch(pred) {
+ case ICmpInst::ICMP_EQ:
+ if (isa<ConstantInt>(C2))
+ return ConstantExpr::getXor(C1, ConstantExpr::getNot(C2));
+ return ConstantExpr::getXor(ConstantExpr::getNot(C1), C2);
+ case ICmpInst::ICMP_NE:
+ return ConstantExpr::getXor(C1, C2);
+ default:
+ break;
+ }
+ }
+
if (isa<ConstantInt>(C1) && isa<ConstantInt>(C2)) {
APInt V1 = cast<ConstantInt>(C1)->getValue();
APInt V2 = cast<ConstantInt>(C2)->getValue();
Modified: llvm/trunk/test/Transforms/ConstProp/2009-09-19-ConstFold-i1-ConstExpr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ConstProp/2009-09-19-ConstFold-i1-ConstExpr.ll?rev=82386&r1=82385&r2=82386&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ConstProp/2009-09-19-ConstFold-i1-ConstExpr.ll (original)
+++ llvm/trunk/test/Transforms/ConstProp/2009-09-19-ConstFold-i1-ConstExpr.ll Sun Sep 20 02:21:39 2009
@@ -27,3 +27,12 @@
; CHECK: @I = global i1 icmp ult (i8* @X, i8* @Y) ; <i1*> [#uses=0]
@J = global i1 xor (i1 icmp ult (i8* @X, i8* @Y), i1 true)
; CHECK: @J = global i1 icmp uge (i8* @X, i8* @Y) ; <i1*> [#uses=0]
+
+ at K = global i1 icmp eq (i1 icmp ult (i8* @X, i8* @Y), i1 false)
+; CHECK: @K = global i1 icmp uge (i8* @X, i8* @Y) ; <i1*> [#uses=0]
+ at L = global i1 icmp eq (i1 icmp ult (i8* @X, i8* @Y), i1 true)
+; CHECK: @L = global i1 icmp ult (i8* @X, i8* @Y) ; <i1*> [#uses=0]
+ at M = global i1 icmp ne (i1 icmp ult (i8* @X, i8* @Y), i1 true)
+; CHECK: @M = global i1 icmp uge (i8* @X, i8* @Y) ; <i1*> [#uses=0]
+ at N = global i1 icmp ne (i1 icmp ult (i8* @X, i8* @Y), i1 false)
+; CHECK: @N = global i1 icmp ult (i8* @X, i8* @Y) ; <i1*> [#uses=0]
More information about the llvm-commits
mailing list