[llvm-commits] [llvm] r82371 - in /llvm/trunk: lib/VMCore/ConstantFold.cpp test/Transforms/ConstProp/2009-09-19-ConstFold-i1-ConstExpr.ll
Nick Lewycky
nicholas at mxc.ca
Sat Sep 19 22:48:50 PDT 2009
Author: nicholas
Date: Sun Sep 20 00:48:50 2009
New Revision: 82371
URL: http://llvm.org/viewvc/llvm-project?rev=82371&view=rev
Log:
Try turning icmp(bitcast(x), bitcast(y)) into icmp(bitcast(bitcast(x)), y) in
the hopes that the two bitcasts will merge.
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=82371&r1=82370&r2=82371&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/ConstantFold.cpp (original)
+++ llvm/trunk/lib/VMCore/ConstantFold.cpp Sun Sep 20 00:48:50 2009
@@ -1627,6 +1627,16 @@
if (Result != -1)
return ConstantInt::get(Type::getInt1Ty(Context), Result);
+ // If the right hand side is a bitcast, try using its inverse to simplify
+ // it by moving it to the left hand side.
+ if (ConstantExpr *CE2 = dyn_cast<ConstantExpr>(C2)) {
+ if (CE2->getOpcode() == Instruction::BitCast) {
+ Constant *CE2Op0 = CE2->getOperand(0);
+ Constant *Inverse = ConstantExpr::getBitCast(C1, CE2Op0->getType());
+ return ConstantExpr::getICmp(pred, Inverse, CE2Op0);
+ }
+ }
+
if (!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) {
// If C2 is a constant expr and C1 isn't, flip them around and fold the
// other way if possible.
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=82371&r1=82370&r2=82371&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 00:48:50 2009
@@ -23,3 +23,8 @@
global i1 urem (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
; CHECK-NOT: icmp
; CHECK: i1 false
+
+global i1 icmp ule (i32* bitcast (i8* @X to i32*), i32* bitcast (i8* @Y to i32*))
+; CHECK-NOT: bitcast
+; CHECK: icmp
+
More information about the llvm-commits
mailing list