[llvm] r223969 - ConstantFold, InstSimplify: undef >>a x can be either -1 or 0, choose 0
David Majnemer
david.majnemer at gmail.com
Wed Dec 10 13:58:16 PST 2014
Author: majnemer
Date: Wed Dec 10 15:58:15 2014
New Revision: 223969
URL: http://llvm.org/viewvc/llvm-project?rev=223969&view=rev
Log:
ConstantFold, InstSimplify: undef >>a x can be either -1 or 0, choose 0
Zero is usually a nicer constant to have than -1.
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/lib/IR/ConstantFold.cpp
llvm/trunk/test/Transforms/InstCombine/shift.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=223969&r1=223968&r2=223969&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Wed Dec 10 15:58:15 2014
@@ -1422,11 +1422,11 @@ static Value *SimplifyAShrInst(Value *Op
if (match(Op0, m_AllOnes()))
return Op0;
- // undef >>a X -> all ones
+ // undef >>a X -> 0
// undef >>a X -> undef (if it's exact)
if (match(Op0, m_Undef()))
return isExact ? UndefValue::get(Op0->getType())
- : Constant::getAllOnesValue(Op0->getType());
+ : Constant::getNullValue(Op0->getType());
// (X << A) >> A -> X
Value *X;
Modified: llvm/trunk/lib/IR/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantFold.cpp?rev=223969&r1=223968&r2=223969&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ConstantFold.cpp (original)
+++ llvm/trunk/lib/IR/ConstantFold.cpp Wed Dec 10 15:58:15 2014
@@ -960,8 +960,9 @@ Constant *llvm::ConstantFoldBinaryInstru
// X >>a undef -> undef
if (isa<UndefValue>(C2))
return C2;
- // undef >>a X -> all ones
- return Constant::getAllOnesValue(C1->getType());
+ // TODO: undef >>a X -> undef if the shift is exact
+ // undef >>a X -> 0
+ return Constant::getNullValue(C1->getType());
case Instruction::Shl:
// X << undef -> undef
if (isa<UndefValue>(C2))
Modified: llvm/trunk/test/Transforms/InstCombine/shift.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/shift.ll?rev=223969&r1=223968&r2=223969&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/shift.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/shift.ll Wed Dec 10 15:58:15 2014
@@ -84,14 +84,14 @@ define <4 x i32> @test5a_non_splat_vecto
define i32 @test5b() {
; CHECK-LABEL: @test5b(
-; CHECK: ret i32 -1
+; CHECK: ret i32 0
%B = ashr i32 undef, 2 ;; top two bits must be equal, so not undef
ret i32 %B
}
define i32 @test5b2(i32 %A) {
; CHECK-LABEL: @test5b2(
-; CHECK: ret i32 -1
+; CHECK: ret i32 0
%B = ashr i32 undef, %A ;; top %A bits must be equal, so not undef
ret i32 %B
}
More information about the llvm-commits
mailing list