From e729e18c399fecb705ed7bed94660140474907bf Mon Sep 17 00:00:00 2001 From: David Sherwood Date: Thu, 11 Sep 2025 08:55:34 +0000 Subject: [PATCH 1/2] [InstSimplify] Simplify get.active.lane.mask when 2nd arg is zero 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. --- llvm/lib/Analysis/InstructionSimplify.cpp | 4 ++++ .../InstSimplify/get_active_lane_mask.ll | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 llvm/test/Transforms/InstSimplify/get_active_lane_mask.ll diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index ebe329aa1d5fe..7bff13d59528c 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -6474,6 +6474,10 @@ Value *llvm::simplifyBinaryIntrinsic(Intrinsic::ID IID, Type *ReturnType, const CallBase *Call) { unsigned BitWidth = ReturnType->getScalarSizeInBits(); switch (IID) { + case Intrinsic::get_active_lane_mask: + if (match(Op1, m_Zero())) + return ConstantInt::getFalse(ReturnType); + break; case Intrinsic::abs: // abs(abs(x)) -> abs(x). We don't need to worry about the nsw arg here. // It is always ok to pick the earlier abs. We'll just lose nsw if its only diff --git a/llvm/test/Transforms/InstSimplify/get_active_lane_mask.ll b/llvm/test/Transforms/InstSimplify/get_active_lane_mask.ll new file mode 100644 index 0000000000000..a3b8e4efbe939 --- /dev/null +++ b/llvm/test/Transforms/InstSimplify/get_active_lane_mask.ll @@ -0,0 +1,20 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 +; RUN: opt < %s -passes=instsimplify,verify -S | FileCheck %s + +define <4 x i1> @foo_v4i1(i32 %a) { +; CHECK-LABEL: define <4 x i1> @foo_v4i1( +; CHECK-SAME: i32 [[A:%.*]]) { +; CHECK-NEXT: ret <4 x i1> zeroinitializer +; + %mask = call <4 x i1> @llvm.get.active.lane.mask.v4i1(i32 %a, i32 0) + ret <4 x i1> %mask +} + +define @foo_nxv8i1(i32 %a) { +; CHECK-LABEL: define @foo_nxv8i1( +; CHECK-SAME: i32 [[A:%.*]]) { +; CHECK-NEXT: ret zeroinitializer +; + %mask = call @llvm.get.active.lane.mask.nxv8i1(i32 %a, i32 0) + ret %mask +} From 2642171f14977a9550f31bdf27b9358006e8e843 Mon Sep 17 00:00:00 2001 From: David Sherwood Date: Fri, 12 Sep 2025 08:42:02 +0000 Subject: [PATCH 2/2] Fix test after rebase --- .../test/Transforms/InstSimplify/ConstProp/active-lane-mask.ll | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/llvm/test/Transforms/InstSimplify/ConstProp/active-lane-mask.ll b/llvm/test/Transforms/InstSimplify/ConstProp/active-lane-mask.ll index 9de0c597305b0..e9d9ac040ea1d 100644 --- a/llvm/test/Transforms/InstSimplify/ConstProp/active-lane-mask.ll +++ b/llvm/test/Transforms/InstSimplify/ConstProp/active-lane-mask.ll @@ -354,8 +354,7 @@ entry: define @nxv16i1_constexpr_0() { ; CHECK-LABEL: @nxv16i1_constexpr_0( ; CHECK-NEXT: entry: -; CHECK-NEXT: [[MASK:%.*]] = call @llvm.get.active.lane.mask.nxv16i1.i64(i64 ptrtoint (ptr @glob to i64), i64 0) -; CHECK-NEXT: ret [[MASK]] +; CHECK-NEXT: ret zeroinitializer ; entry: %mask = call @llvm.get.active.lane.mask.nxv16i1.i64(i64 ptrtoint (ptr @glob to i64), i64 0)