summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp8
-rw-r--r--llvm/test/Transforms/InstSimplify/undef.ll14
2 files changed, 20 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 767b42b4bd7..1c5a917cbec 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -1387,8 +1387,10 @@ static Value *SimplifyLShrInst(Value *Op0, Value *Op1, bool isExact,
return V;
// undef >>l X -> 0
+ // undef >>l X -> undef (if it's exact)
if (match(Op0, m_Undef()))
- return Constant::getNullValue(Op0->getType());
+ return isExact ? UndefValue::get(Op0->getType())
+ : Constant::getNullValue(Op0->getType());
// (X << A) >> A -> X
Value *X;
@@ -1421,8 +1423,10 @@ static Value *SimplifyAShrInst(Value *Op0, Value *Op1, bool isExact,
return Op0;
// undef >>a X -> all ones
+ // undef >>a X -> undef (if it's exact)
if (match(Op0, m_Undef()))
- return Constant::getAllOnesValue(Op0->getType());
+ return isExact ? UndefValue::get(Op0->getType())
+ : Constant::getAllOnesValue(Op0->getType());
// (X << A) >> A -> X
Value *X;
diff --git a/llvm/test/Transforms/InstSimplify/undef.ll b/llvm/test/Transforms/InstSimplify/undef.ll
index a6ae7a9fbf7..3742d7450af 100644
--- a/llvm/test/Transforms/InstSimplify/undef.ll
+++ b/llvm/test/Transforms/InstSimplify/undef.ll
@@ -174,3 +174,17 @@ define i32 @test21(i32 %a) {
%b = sdiv i32 %a, 0
ret i32 %b
}
+
+; CHECK-LABEL: @test22
+; CHECK: ret i32 undef
+define i32 @test22(i32 %a) {
+ %b = ashr exact i32 undef, %a
+ ret i32 %b
+}
+
+; CHECK-LABEL: @test23
+; CHECK: ret i32 undef
+define i32 @test23(i32 %a) {
+ %b = lshr exact i32 undef, %a
+ ret i32 %b
+}
OpenPOWER on IntegriCloud