diff options
author | Dan Gohman <gohman@apple.com> | 2010-06-28 21:30:07 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-06-28 21:30:07 +0000 |
commit | e697a6f24f571c690bf196700f69a316b803563f (patch) | |
tree | 9934378a3638c5d8a796fe3b79504e476d5a4900 | |
parent | f31c004666a4e507d1a3fee0272ee51634dcfd78 (diff) | |
download | bcm5719-llvm-e697a6f24f571c690bf196700f69a316b803563f.tar.gz bcm5719-llvm-e697a6f24f571c690bf196700f69a316b803563f.zip |
Constant fold x == undef to undef.
llvm-svn: 107074
-rw-r--r-- | llvm/lib/VMCore/ConstantFold.cpp | 9 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/icmp.ll | 23 |
2 files changed, 31 insertions, 1 deletions
diff --git a/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp index ec62502ae4d..35672661e44 100644 --- a/llvm/lib/VMCore/ConstantFold.cpp +++ b/llvm/lib/VMCore/ConstantFold.cpp @@ -1817,8 +1817,15 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred, return Constant::getAllOnesValue(ResultTy); // Handle some degenerate cases first - if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) + if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) { + // For EQ and NE, we can always pick a value for the undef to make the + // predicate pass or fail, so we can return undef. + if (ICmpInst::isEquality(ICmpInst::Predicate(pred))) + return UndefValue::get(ResultTy); + // Otherwise, pick the same value as the non-undef operand, and fold + // it to true or false. return ConstantInt::get(ResultTy, CmpInst::isTrueWhenEqual(pred)); + } // No compile-time operations on this type yet. if (C1->getType()->isPPC_FP128Ty()) diff --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll index 29997bf8c41..802957f47b3 100644 --- a/llvm/test/Transforms/InstCombine/icmp.ll +++ b/llvm/test/Transforms/InstCombine/icmp.ll @@ -131,3 +131,26 @@ entry: ; CHECK: ret i1 false } +define i1 @test14(i8 %X) nounwind readnone { +entry: + %cmp = icmp slt i8 undef, -128 + ret i1 %cmp +; CHECK: @test14 +; CHECK: ret i1 false +} + +define i1 @test15() nounwind readnone { +entry: + %cmp = icmp eq i8 undef, -128 + ret i1 %cmp +; CHECK: @test15 +; CHECK: ret i1 undef +} + +define i1 @test16() nounwind readnone { +entry: + %cmp = icmp ne i8 undef, -128 + ret i1 %cmp +; CHECK: @test16 +; CHECK: ret i1 undef +} |