[llvm] b2de846 - [ConstProp] Don't fallthorugh for poison constants on vctp and active_lane_mask.

David Green via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 5 03:19:49 PDT 2022


Author: David Green
Date: 2022-08-05T11:19:36+01:00
New Revision: b2de84633a0a262b894e7cf87d29b167787aa2d6

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

LOG: [ConstProp] Don't fallthorugh for poison constants on vctp and active_lane_mask.

Given a poison constant as input, the dyn_cast to a ConstantInt would
fail so we would fall through to the generic code that attempts to fold
each element of the input vectors. The inputs to these intrinsics are
not vectors though, leading to a compile time crash. Instead bail out
properly for poison values by returning nullptr. This doesn't try to
define what poison means for these intrinsics.

Fixes #56945

Added: 
    

Modified: 
    llvm/lib/Analysis/ConstantFolding.cpp
    llvm/test/Transforms/InstSimplify/ConstProp/ARM/mve-vctp.ll
    llvm/test/Transforms/InstSimplify/ConstProp/active-lane-mask.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index f8d05eb688e32..38fb50347c301 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -3120,7 +3120,7 @@ static Constant *ConstantFoldFixedVectorCall(
       }
       return ConstantVector::get(NCs);
     }
-    break;
+    return nullptr;
   }
   case Intrinsic::get_active_lane_mask: {
     auto *Op0 = dyn_cast<ConstantInt>(Operands[0]);
@@ -3139,7 +3139,7 @@ static Constant *ConstantFoldFixedVectorCall(
       }
       return ConstantVector::get(NCs);
     }
-    break;
+    return nullptr;
   }
   default:
     break;

diff  --git a/llvm/test/Transforms/InstSimplify/ConstProp/ARM/mve-vctp.ll b/llvm/test/Transforms/InstSimplify/ConstProp/ARM/mve-vctp.ll
index 34aea14b594c5..979fb2e84ba92 100644
--- a/llvm/test/Transforms/InstSimplify/ConstProp/ARM/mve-vctp.ll
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/ARM/mve-vctp.ll
@@ -259,7 +259,14 @@ entry:
   ret <2 x i1> %int
 }
 
-
+define <4 x float> @poisonc(<4 x float> %a) {
+entry:
+  %new0 = shl i1 0, 1
+  %last = zext i1 %new0 to i32
+  %var27 = call <4 x i1> @llvm.arm.mve.vctp32(i32 %last)
+  %var33 = select <4 x i1> %var27, <4 x float> %a, <4 x float> zeroinitializer
+  ret <4 x float> %var33
+}
 
 declare <2 x i1> @llvm.arm.mve.vctp64(i32)
 declare <4 x i1> @llvm.arm.mve.vctp32(i32)

diff  --git a/llvm/test/Transforms/InstSimplify/ConstProp/active-lane-mask.ll b/llvm/test/Transforms/InstSimplify/ConstProp/active-lane-mask.ll
index 7260381222896..4a879e837f835 100644
--- a/llvm/test/Transforms/InstSimplify/ConstProp/active-lane-mask.ll
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/active-lane-mask.ll
@@ -292,8 +292,14 @@ entry:
 }
 
 
-
-
+define <4 x float> @poisonc(<4 x float> %a, i32 %n) {
+entry:
+  %new0 = shl i1 0, 1
+  %last = zext i1 %new0 to i32
+  %var27 = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 %last, i32 1024)
+  %var33 = select <4 x i1> %var27, <4 x float> %a, <4 x float> zeroinitializer
+  ret <4 x float> %var33
+}
 
 declare <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32, i32)
 declare <8 x i1> @llvm.get.active.lane.mask.v8i1.i32(i32, i32)


        


More information about the llvm-commits mailing list