[llvm] r224553 - ConstantFold: Shifting undef by zero results in undef
David Majnemer
david.majnemer at gmail.com
Thu Dec 18 15:54:44 PST 2014
Author: majnemer
Date: Thu Dec 18 17:54:43 2014
New Revision: 224553
URL: http://llvm.org/viewvc/llvm-project?rev=224553&view=rev
Log:
ConstantFold: Shifting undef by zero results in undef
Modified:
llvm/trunk/lib/IR/ConstantFold.cpp
llvm/trunk/test/Transforms/InstSimplify/undef.ll
Modified: llvm/trunk/lib/IR/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantFold.cpp?rev=224553&r1=224552&r2=224553&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ConstantFold.cpp (original)
+++ llvm/trunk/lib/IR/ConstantFold.cpp Thu Dec 18 17:54:43 2014
@@ -956,12 +956,18 @@ Constant *llvm::ConstantFoldBinaryInstru
// X >>l undef -> undef
if (isa<UndefValue>(C2))
return C2;
+ // undef >>l 0 -> undef
+ if (match(C2, m_Zero()))
+ return C1;
// undef >>l X -> 0
return Constant::getNullValue(C1->getType());
case Instruction::AShr:
// X >>a undef -> undef
if (isa<UndefValue>(C2))
return C2;
+ // undef >>a 0 -> undef
+ if (match(C2, m_Zero()))
+ return C1;
// TODO: undef >>a X -> undef if the shift is exact
// undef >>a X -> 0
return Constant::getNullValue(C1->getType());
@@ -969,6 +975,9 @@ Constant *llvm::ConstantFoldBinaryInstru
// X << undef -> undef
if (isa<UndefValue>(C2))
return C2;
+ // undef << 0 -> undef
+ if (match(C2, m_Zero()))
+ return C1;
// undef << X -> 0
return Constant::getNullValue(C1->getType());
}
Modified: llvm/trunk/test/Transforms/InstSimplify/undef.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/undef.ll?rev=224553&r1=224552&r2=224553&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/undef.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/undef.ll Thu Dec 18 17:54:43 2014
@@ -244,3 +244,24 @@ define i32 @test31(i32 %a) {
%b = shl i32 undef, %a
ret i32 %b
}
+
+; CHECK-LABEL: @test32
+; CHECK: ret i32 undef
+define i32 @test32(i32 %a) {
+ %b = shl i32 undef, 0
+ ret i32 %b
+}
+
+; CHECK-LABEL: @test33
+; CHECK: ret i32 undef
+define i32 @test33(i32 %a) {
+ %b = ashr i32 undef, 0
+ ret i32 %b
+}
+
+; CHECK-LABEL: @test34
+; CHECK: ret i32 undef
+define i32 @test34(i32 %a) {
+ %b = lshr i32 undef, 0
+ ret i32 %b
+}
More information about the llvm-commits
mailing list