[llvm] 74b5e79 - [InstSimplify] fold scalable vectors with over-shift splat constant to poison

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 7 13:30:15 PDT 2022


Author: Sanjay Patel
Date: 2022-08-07T16:26:05-04:00
New Revision: 74b5e797d5c9364bfc733f07ed9d27a33853f57b

URL: https://github.com/llvm/llvm-project/commit/74b5e797d5c9364bfc733f07ed9d27a33853f57b
DIFF: https://github.com/llvm/llvm-project/commit/74b5e797d5c9364bfc733f07ed9d27a33853f57b.diff

LOG: [InstSimplify] fold scalable vectors with over-shift splat constant to poison

Fixes #56968

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp
    llvm/test/Transforms/InstSimplify/shift.ll

Removed: 
    


################################################################################
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


        


More information about the llvm-commits mailing list