Skip to content

Commit 1f49c94

Browse files
authored
[InstSimplify] Simplify get.active.lane.mask when 2nd arg is zero (#158018)
When the second argument passed to the get.active.lane.mask intrinsic is zero we can simplify the instruction to return an all-false mask regardless of the first operand.
1 parent 14ae5f3 commit 1f49c94

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6474,6 +6474,10 @@ Value *llvm::simplifyBinaryIntrinsic(Intrinsic::ID IID, Type *ReturnType,
64746474
const CallBase *Call) {
64756475
unsigned BitWidth = ReturnType->getScalarSizeInBits();
64766476
switch (IID) {
6477+
case Intrinsic::get_active_lane_mask:
6478+
if (match(Op1, m_Zero()))
6479+
return ConstantInt::getFalse(ReturnType);
6480+
break;
64776481
case Intrinsic::abs:
64786482
// abs(abs(x)) -> abs(x). We don't need to worry about the nsw arg here.
64796483
// It is always ok to pick the earlier abs. We'll just lose nsw if its only

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,7 @@ entry:
354354
define <vscale x 16 x i1> @nxv16i1_constexpr_0() {
355355
; CHECK-LABEL: @nxv16i1_constexpr_0(
356356
; CHECK-NEXT: entry:
357-
; CHECK-NEXT: [[MASK:%.*]] = call <vscale x 16 x i1> @llvm.get.active.lane.mask.nxv16i1.i64(i64 ptrtoint (ptr @glob to i64), i64 0)
358-
; CHECK-NEXT: ret <vscale x 16 x i1> [[MASK]]
357+
; CHECK-NEXT: ret <vscale x 16 x i1> zeroinitializer
359358
;
360359
entry:
361360
%mask = call <vscale x 16 x i1> @llvm.get.active.lane.mask.nxv16i1.i64(i64 ptrtoint (ptr @glob to i64), i64 0)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt < %s -passes=instsimplify,verify -S | FileCheck %s
3+
4+
define <4 x i1> @foo_v4i1(i32 %a) {
5+
; CHECK-LABEL: define <4 x i1> @foo_v4i1(
6+
; CHECK-SAME: i32 [[A:%.*]]) {
7+
; CHECK-NEXT: ret <4 x i1> zeroinitializer
8+
;
9+
%mask = call <4 x i1> @llvm.get.active.lane.mask.v4i1(i32 %a, i32 0)
10+
ret <4 x i1> %mask
11+
}
12+
13+
define <vscale x 8 x i1> @foo_nxv8i1(i32 %a) {
14+
; CHECK-LABEL: define <vscale x 8 x i1> @foo_nxv8i1(
15+
; CHECK-SAME: i32 [[A:%.*]]) {
16+
; CHECK-NEXT: ret <vscale x 8 x i1> zeroinitializer
17+
;
18+
%mask = call <vscale x 8 x i1> @llvm.get.active.lane.mask.nxv8i1(i32 %a, i32 0)
19+
ret <vscale x 8 x i1> %mask
20+
}

0 commit comments

Comments
 (0)