diff options
-rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 12 | ||||
-rw-r--r-- | llvm/test/Transforms/InstSimplify/shift.ll | 3 |
2 files changed, 8 insertions, 7 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 9cebbbdfe762..a4f26c842dbc 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -1252,12 +1252,14 @@ static bool isPoisonShift(Value *Amount, const SimplifyQuery &Q) { if (Q.isUndefValue(C)) return true; - // Shifting by the bitwidth or more is undefined. - if (ConstantInt *CI = dyn_cast<ConstantInt>(C)) - if (CI->getValue().uge(CI->getType()->getScalarSizeInBits())) - return true; + // Shifting by the bitwidth or more is poison. This covers scalars and + // fixed/scalable vectors with splat constants. + const APInt *AmountC; + if (match(C, m_APInt(AmountC)) && AmountC->uge(AmountC->getBitWidth())) + return true; - // If all lanes of a vector shift are undefined the whole shift is. + // Try harder for fixed-length vectors: + // If all lanes of a vector shift are poison, the whole shift is poison. if (isa<ConstantVector>(C) || isa<ConstantDataVector>(C)) { for (unsigned I = 0, E = cast<FixedVectorType>(C->getType())->getNumElements(); diff --git a/llvm/test/Transforms/InstSimplify/shift.ll b/llvm/test/Transforms/InstSimplify/shift.ll index 8f2f02600ded..9b145813b587 100644 --- a/llvm/test/Transforms/InstSimplify/shift.ll +++ b/llvm/test/Transforms/InstSimplify/shift.ll @@ -345,8 +345,7 @@ define i32 @all_ones_left_right_not_same_shift(i32 %x, i32 %y) { define <vscale x 4 x i16> @lshr_scalable_overshift(<vscale x 4 x i16> %va) { ; CHECK-LABEL: @lshr_scalable_overshift( -; CHECK-NEXT: [[VC:%.*]] = lshr <vscale x 4 x i16> [[VA:%.*]], shufflevector (<vscale x 4 x i16> insertelement (<vscale x 4 x i16> poison, i16 16, i32 0), <vscale x 4 x i16> poison, <vscale x 4 x i32> zeroinitializer) -; CHECK-NEXT: ret <vscale x 4 x i16> [[VC]] +; CHECK-NEXT: ret <vscale x 4 x i16> poison ; %vc = lshr <vscale x 4 x i16> %va, shufflevector (<vscale x 4 x i16> insertelement (<vscale x 4 x i16> poison, i16 16, i32 0), <vscale x 4 x i16> poison, <vscale x 4 x i32> zeroinitializer) ret <vscale x 4 x i16> %vc |