Skip to content

Commit b2de846

Browse files
committed
[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
1 parent c401dbd commit b2de846

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3120,7 +3120,7 @@ static Constant *ConstantFoldFixedVectorCall(
31203120
}
31213121
return ConstantVector::get(NCs);
31223122
}
3123-
break;
3123+
return nullptr;
31243124
}
31253125
case Intrinsic::get_active_lane_mask: {
31263126
auto *Op0 = dyn_cast<ConstantInt>(Operands[0]);
@@ -3139,7 +3139,7 @@ static Constant *ConstantFoldFixedVectorCall(
31393139
}
31403140
return ConstantVector::get(NCs);
31413141
}
3142-
break;
3142+
return nullptr;
31433143
}
31443144
default:
31453145
break;

llvm/test/Transforms/InstSimplify/ConstProp/ARM/mve-vctp.ll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,14 @@ entry:
259259
ret <2 x i1> %int
260260
}
261261

262-
262+
define <4 x float> @poisonc(<4 x float> %a) {
263+
entry:
264+
%new0 = shl i1 0, 1
265+
%last = zext i1 %new0 to i32
266+
%var27 = call <4 x i1> @llvm.arm.mve.vctp32(i32 %last)
267+
%var33 = select <4 x i1> %var27, <4 x float> %a, <4 x float> zeroinitializer
268+
ret <4 x float> %var33
269+
}
263270

264271
declare <2 x i1> @llvm.arm.mve.vctp64(i32)
265272
declare <4 x i1> @llvm.arm.mve.vctp32(i32)

llvm/test/Transforms/InstSimplify/ConstProp/active-lane-mask.ll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,14 @@ entry:
292292
}
293293

294294

295-
296-
295+
define <4 x float> @poisonc(<4 x float> %a, i32 %n) {
296+
entry:
297+
%new0 = shl i1 0, 1
298+
%last = zext i1 %new0 to i32
299+
%var27 = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 %last, i32 1024)
300+
%var33 = select <4 x i1> %var27, <4 x float> %a, <4 x float> zeroinitializer
301+
ret <4 x float> %var33
302+
}
297303

298304
declare <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32, i32)
299305
declare <8 x i1> @llvm.get.active.lane.mask.v8i1.i32(i32, i32)

0 commit comments

Comments
 (0)