[llvm-commits] [llvm] r97659 - in /llvm/trunk: lib/Analysis/InstructionSimplify.cpp lib/VMCore/ConstantFold.cpp test/Transforms/InstCombine/icmp.ll
Chris Lattner
sabre at nondot.org
Wed Mar 3 11:46:03 PST 2010
Author: lattner
Date: Wed Mar 3 13:46:03 2010
New Revision: 97659
URL: http://llvm.org/viewvc/llvm-project?rev=97659&view=rev
Log:
fix incorrect folding of icmp with undef, PR6481.
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/lib/VMCore/ConstantFold.cpp
llvm/trunk/test/Transforms/InstCombine/icmp.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=97659&r1=97658&r2=97659&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Wed Mar 3 13:46:03 2010
@@ -194,11 +194,10 @@
const Type *ITy = GetCompareTy(LHS);
// icmp X, X -> true/false
- if (LHS == RHS)
+ // X icmp undef -> true/false. For example, icmp ugt %X, undef -> false
+ // because X could be 0.
+ if (LHS == RHS || isa<UndefValue>(RHS))
return ConstantInt::get(ITy, CmpInst::isTrueWhenEqual(Pred));
-
- if (isa<UndefValue>(RHS)) // X icmp undef -> undef
- return UndefValue::get(ITy);
// icmp <global/alloca*/null>, <global/alloca*/null> - Global/Stack value
// addresses never equal each other! We already know that Op0 != Op1.
Modified: llvm/trunk/lib/VMCore/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ConstantFold.cpp?rev=97659&r1=97658&r2=97659&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/ConstantFold.cpp (original)
+++ llvm/trunk/lib/VMCore/ConstantFold.cpp Wed Mar 3 13:46:03 2010
@@ -1818,7 +1818,7 @@
// Handle some degenerate cases first
if (isa<UndefValue>(C1) || isa<UndefValue>(C2))
- return UndefValue::get(ResultTy);
+ return ConstantInt::get(ResultTy, CmpInst::isTrueWhenEqual(pred));
// No compile-time operations on this type yet.
if (C1->getType()->isPPC_FP128Ty())
Modified: llvm/trunk/test/Transforms/InstCombine/icmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp.ll?rev=97659&r1=97658&r2=97659&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/icmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/icmp.ll Wed Mar 3 13:46:03 2010
@@ -48,7 +48,7 @@
%V = icmp eq <2 x i64> %x, undef
ret <2 x i1> %V
; CHECK: @test5
-; CHECK: ret <2 x i1> undef
+; CHECK: ret <2 x i1> <i1 true, i1 true>
}
define i32 @test6(i32 %a, i32 %b) {
@@ -121,3 +121,13 @@
; CHECK-NEXT: %B = select i1
; CHECK-NEXT: ret i1 %B
}
+
+; PR6481
+define i1 @test13(i8 %X) nounwind readnone {
+entry:
+ %cmp = icmp slt i8 undef, %X
+ ret i1 %cmp
+; CHECK: @test13
+; CHECK: ret i1 false
+}
+
More information about the llvm-commits
mailing list