[PATCH] D77739: [InstCombine] replace undef in vector constant for safe shift transform (PR45447)
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 9 05:23:49 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG812970edda36: [InstCombine] replace undef in vector constant for safe shift transform… (authored by spatel).
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D77739/new/
https://reviews.llvm.org/D77739
Files:
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/test/Transforms/InstCombine/vector-xor.ll
Index: llvm/test/Transforms/InstCombine/vector-xor.ll
===================================================================
--- llvm/test/Transforms/InstCombine/vector-xor.ll
+++ llvm/test/Transforms/InstCombine/vector-xor.ll
@@ -172,7 +172,7 @@
define <4 x i32> @test_v4i32_not_lshr_nonnegative_const_undef(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_not_lshr_nonnegative_const_undef(
-; CHECK-NEXT: [[TMP1:%.*]] = ashr <4 x i32> <i32 -4, i32 -6, i32 undef, i32 -10>, [[A0:%.*]]
+; CHECK-NEXT: [[TMP1:%.*]] = ashr <4 x i32> <i32 -4, i32 -6, i32 -1, i32 -10>, [[A0:%.*]]
; CHECK-NEXT: ret <4 x i32> [[TMP1]]
;
%1 = lshr <4 x i32> <i32 3, i32 5, i32 undef, i32 9>, %a0
Index: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -3071,16 +3071,22 @@
Constant *C;
if (match(NotVal, m_AShr(m_Constant(C), m_Value(Y))) &&
match(C, m_Negative())) {
- Constant *NewC = ConstantExpr::getNot(C);
- if (C->getType()->isVectorTy())
- NewC = getSafeVectorConstantForBinop(Instruction::LShr, NewC, false);
- return BinaryOperator::CreateLShr(NewC, Y);
+ // We matched a negative constant, so propagating undef is unsafe.
+ // Clamp undef elements to -1.
+ Type *EltTy = C->getType()->getScalarType();
+ C = Constant::replaceUndefsWith(C, ConstantInt::getAllOnesValue(EltTy));
+ return BinaryOperator::CreateLShr(ConstantExpr::getNot(C), Y);
}
// ~(C >>u Y) --> ~C >>s Y (when inverting the replicated sign bits)
if (match(NotVal, m_LShr(m_Constant(C), m_Value(Y))) &&
- match(C, m_NonNegative()))
+ match(C, m_NonNegative())) {
+ // We matched a non-negative constant, so propagating undef is unsafe.
+ // Clamp undef elements to 0.
+ Type *EltTy = C->getType()->getScalarType();
+ C = Constant::replaceUndefsWith(C, ConstantInt::getNullValue(EltTy));
return BinaryOperator::CreateAShr(ConstantExpr::getNot(C), Y);
+ }
// ~(X + C) --> -(C + 1) - X
if (match(Op0, m_Add(m_Value(X), m_Constant(C))))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77739.256256.patch
Type: text/x-patch
Size: 2238 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200409/6f97498e/attachment.bin>
More information about the llvm-commits
mailing list