[llvm] [SelectionDAG] Add support for extending masked loads in computeKnownBits (PR #115450)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 8 01:45:07 PST 2024
https://github.com/david-arm created https://github.com/llvm/llvm-project/pull/115450
We already support computing known bits for extending loads, but not for masked loads. For now I've only added support for zero-extends because that's the only thing currently tested. Even when the passthru value is poison we still know the top X bits are zero.
>From f7a7167ecc4c478aca8d8222987d943beb84e5ee Mon Sep 17 00:00:00 2001
From: David Sherwood <david.sherwood at arm.com>
Date: Fri, 8 Nov 2024 09:42:11 +0000
Subject: [PATCH] [SelectionDAG] Add support for extending masked loads in
computeKnownBits
We already support computing known bits for extending loads, but not
for masked loads. For now I've only added support for zero-extends
because that's the only thing currently tested. Even when the passthru
value is poison we still know the top X bits are zero.
---
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 13 +++++++++++++
llvm/test/CodeGen/AArch64/sve-hadd.ll | 14 ++++++--------
2 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 203e14f6cde3e3..901e63c47fac17 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -3920,6 +3920,19 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
Known.Zero.setBitsFrom(1);
break;
}
+ case ISD::MGATHER:
+ case ISD::MLOAD: {
+ ISD::LoadExtType ETy =
+ (Opcode == ISD::MGATHER)
+ ? cast<MaskedGatherSDNode>(Op)->getExtensionType()
+ : cast<MaskedLoadSDNode>(Op)->getExtensionType();
+ if (ETy == ISD::ZEXTLOAD) {
+ EVT MemVT = cast<MemSDNode>(Op)->getMemoryVT();
+ KnownBits Known0(MemVT.getScalarSizeInBits());
+ return Known0.zext(BitWidth);
+ }
+ break;
+ }
case ISD::LOAD: {
LoadSDNode *LD = cast<LoadSDNode>(Op);
const Constant *Cst = TLI->getTargetConstantFromLoad(LD);
diff --git a/llvm/test/CodeGen/AArch64/sve-hadd.ll b/llvm/test/CodeGen/AArch64/sve-hadd.ll
index 857a883d80ea3d..978ee4534e5e1a 100644
--- a/llvm/test/CodeGen/AArch64/sve-hadd.ll
+++ b/llvm/test/CodeGen/AArch64/sve-hadd.ll
@@ -1347,10 +1347,8 @@ define void @zext_mload_avgflooru(ptr %p1, ptr %p2, <vscale x 8 x i1> %mask) {
; SVE: // %bb.0:
; SVE-NEXT: ld1b { z0.h }, p0/z, [x0]
; SVE-NEXT: ld1b { z1.h }, p0/z, [x1]
-; SVE-NEXT: eor z2.d, z0.d, z1.d
-; SVE-NEXT: and z0.d, z0.d, z1.d
-; SVE-NEXT: lsr z1.h, z2.h, #1
; SVE-NEXT: add z0.h, z0.h, z1.h
+; SVE-NEXT: lsr z0.h, z0.h, #1
; SVE-NEXT: st1h { z0.h }, p0, [x0]
; SVE-NEXT: ret
;
@@ -1377,11 +1375,11 @@ define void @zext_mload_avgceilu(ptr %p1, ptr %p2, <vscale x 8 x i1> %mask) {
; SVE-LABEL: zext_mload_avgceilu:
; SVE: // %bb.0:
; SVE-NEXT: ld1b { z0.h }, p0/z, [x0]
-; SVE-NEXT: ld1b { z1.h }, p0/z, [x1]
-; SVE-NEXT: eor z2.d, z0.d, z1.d
-; SVE-NEXT: orr z0.d, z0.d, z1.d
-; SVE-NEXT: lsr z1.h, z2.h, #1
-; SVE-NEXT: sub z0.h, z0.h, z1.h
+; SVE-NEXT: mov z1.h, #-1 // =0xffffffffffffffff
+; SVE-NEXT: ld1b { z2.h }, p0/z, [x1]
+; SVE-NEXT: eor z0.d, z0.d, z1.d
+; SVE-NEXT: sub z0.h, z2.h, z0.h
+; SVE-NEXT: lsr z0.h, z0.h, #1
; SVE-NEXT: st1b { z0.h }, p0, [x0]
; SVE-NEXT: ret
;
More information about the llvm-commits
mailing list