[llvm] [ARM] Adjust profitability check on and(anyext, c) -> zext(and) transfor… (PR #217956)

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 21 10:21:34 PDT 2026


https://github.com/AZero13 updated https://github.com/llvm/llvm-project/pull/217956

>From 6a4c4b2bb7b2459f8b5354127807f0a0ff12573c Mon Sep 17 00:00:00 2001
From: AZero13 <gfunni234 at gmail.com>
Date: Fri, 21 Aug 2026 11:49:42 -0400
Subject: [PATCH] [ARM] Adjust profitability check on and(anyext, c) ->
 zext(and) transform

Extends the check done in commit 8a34f9d127e52586c7285fa07efd1b6b8e428ca0 for ARM.

Extends the check done in commit 8a34f9d for ARM. A basic version of isNarrowingProfitable is added for ARM to allow vector types to fold providing that the result type is legal.
---
 llvm/lib/Target/ARM/ARMISelLowering.cpp | 5 +++++
 llvm/lib/Target/ARM/ARMISelLowering.h   | 2 ++
 llvm/test/CodeGen/ARM/bool-ext-inc.ll   | 5 ++---
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp
index 43013b1992b50..453d3a34e0b8b 100644
--- a/llvm/lib/Target/ARM/ARMISelLowering.cpp
+++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp
@@ -13807,6 +13807,11 @@ static SDValue PerformADDVecReduce(SDNode *N, SelectionDAG &DAG,
   return SDValue();
 }
 
+bool ARMTargetLowering::isNarrowingProfitable(SDNode *N, EVT SrcVT,
+                                              EVT DestVT) const {
+  return isTypeLegal(DestVT) && DestVT.isVector();
+}
+
 bool
 ARMTargetLowering::isDesirableToCommuteWithShift(const SDNode *N,
                                                  CombineLevel Level) const {
diff --git a/llvm/lib/Target/ARM/ARMISelLowering.h b/llvm/lib/Target/ARM/ARMISelLowering.h
index 4f95a1cdeb2ef..b22dbbc302287 100644
--- a/llvm/lib/Target/ARM/ARMISelLowering.h
+++ b/llvm/lib/Target/ARM/ARMISelLowering.h
@@ -469,6 +469,8 @@ class VectorType;
     Align getABIAlignmentForCallingConv(Type *ArgTy,
                                         const DataLayout &DL) const override;
 
+    bool isNarrowingProfitable(SDNode *N, EVT SrcVT, EVT DestVT) const override;
+
     bool isDesirableToCommuteWithShift(const SDNode *N,
                                        CombineLevel Level) const override;
 
diff --git a/llvm/test/CodeGen/ARM/bool-ext-inc.ll b/llvm/test/CodeGen/ARM/bool-ext-inc.ll
index 00a7fcdee3caa..11e86b212145b 100644
--- a/llvm/test/CodeGen/ARM/bool-ext-inc.ll
+++ b/llvm/test/CodeGen/ARM/bool-ext-inc.ll
@@ -16,10 +16,9 @@ define <4 x i32> @sext_inc_vec(<4 x i1> %x) {
 ; CHECK:       @ %bb.0:
 ; CHECK-NEXT:    vmov.i16 d16, #0x1
 ; CHECK-NEXT:    vmov d17, r0, r1
-; CHECK-NEXT:    veor d16, d17, d16
-; CHECK-NEXT:    vmov.i32 q9, #0x1
+; CHECK-NEXT:    veor d17, d17, d16
+; CHECK-NEXT:    vand d16, d17, d16
 ; CHECK-NEXT:    vmovl.u16 q8, d16
-; CHECK-NEXT:    vand q8, q8, q9
 ; CHECK-NEXT:    vmov r0, r1, d16
 ; CHECK-NEXT:    vmov r2, r3, d17
 ; CHECK-NEXT:    mov pc, lr



More information about the llvm-commits mailing list