Repository navigation
[AArch64] Don't fold expandloads/compressstores into (de)interleave ops - #239160
Merged
Merged
Conversation
Previously, `performVector(De)interleaveCombine` would miscompile by combining expandloads and compressstores with deinterleaves and interleaves respectively. This is fixed by updating `ISD::isNormalMaskedLoad()` and `ISD::isNormalMaskedStore()` to exclude isExpandingLoad() and isCompressingStore().
|
@llvm/pr-subscribers-backend-aarch64 @llvm/pr-subscribers-llvm-selectiondag Author: Benjamin Maxwell (MacDue) ChangesPreviously, This is fixed by updating 3 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
index 40d44f8b924ce..5dd62ffc5e7ae 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
@@ -3507,20 +3507,21 @@ namespace ISD {
return St && St->getAddressingMode() == ISD::UNINDEXED;
}
- /// Returns true if the specified node is a non-extending and unindexed
- /// masked load.
+ /// Returns true if the specified node is a non-extending, non-expanding, and
+ /// unindexed masked load.
inline bool isNormalMaskedLoad(const SDNode *N) {
auto *Ld = dyn_cast<MaskedLoadSDNode>(N);
return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
- Ld->getAddressingMode() == ISD::UNINDEXED;
+ Ld->getAddressingMode() == ISD::UNINDEXED && !Ld->isExpandingLoad();
}
- /// Returns true if the specified node is a non-extending and unindexed
- /// masked store.
+ /// Returns true if the specified node is a non-extending, non-compressing,
+ /// and unindexed masked store.
inline bool isNormalMaskedStore(const SDNode *N) {
auto *St = dyn_cast<MaskedStoreSDNode>(N);
return St && !St->isTruncatingStore() &&
- St->getAddressingMode() == ISD::UNINDEXED;
+ St->getAddressingMode() == ISD::UNINDEXED &&
+ !St->isCompressingStore();
}
/// Attempt to match a unary predicate against a scalar/splat constant or
diff --git a/llvm/test/CodeGen/AArch64/scalable_masked_deinterleaved_loads.ll b/llvm/test/CodeGen/AArch64/scalable_masked_deinterleaved_loads.ll
index f5129c7c57826..1b141e2da36bf 100644
--- a/llvm/test/CodeGen/AArch64/scalable_masked_deinterleaved_loads.ll
+++ b/llvm/test/CodeGen/AArch64/scalable_masked_deinterleaved_loads.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
-; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve2p2 < %s | FileCheck %s
define { <vscale x 16 x i8>, <vscale x 16 x i8> } @foo_ld2_nxv16i8(<vscale x 16 x i1> %mask, ptr %p) {
; CHECK-LABEL: foo_ld2_nxv16i8:
@@ -325,3 +325,26 @@ define { <vscale x 4 x i16>, <vscale x 4 x i16> } @foo_ld2_nxv8i8_exti16(<vscale
%deinterleaved.vec = call { <vscale x 4 x i16>, <vscale x 4 x i16> } @llvm.vector.deinterleave2.nxv8i16(<vscale x 8 x i16> %wide.masked.vec.ext)
ret { <vscale x 4 x i16>, <vscale x 4 x i16> } %deinterleaved.vec
}
+
+; Negative test: An expandload cannot be folded with a vector deinterleave into a ld2.
+define { <vscale x 2 x i64>, <vscale x 2 x i64> } @do_not_fold_expandload_deinterleave(ptr %base, <vscale x 2 x i1> %mask) {
+; CHECK-LABEL: do_not_fold_expandload_deinterleave:
+; CHECK: // %bb.0:
+; CHECK-NEXT: zip2 p1.d, p0.d, p0.d
+; CHECK-NEXT: zip1 p0.d, p0.d, p0.d
+; CHECK-NEXT: cntp x8, p1, p1.d
+; CHECK-NEXT: cntp x9, p0, p0.d
+; CHECK-NEXT: whilelo p2.d, xzr, x8
+; CHECK-NEXT: whilelo p3.d, xzr, x9
+; CHECK-NEXT: ld1d { z0.d }, p2/z, [x0, x9, lsl #3]
+; CHECK-NEXT: ld1d { z1.d }, p3/z, [x0]
+; CHECK-NEXT: expand z2.d, p1, z0.d
+; CHECK-NEXT: expand z1.d, p0, z1.d
+; CHECK-NEXT: uzp1 z0.d, z1.d, z2.d
+; CHECK-NEXT: uzp2 z1.d, z1.d, z2.d
+; CHECK-NEXT: ret
+ %interleaved.mask = call <vscale x 4 x i1> @llvm.vector.interleave2.nxv4i1(<vscale x 2 x i1> %mask, <vscale x 2 x i1> %mask)
+ %wide.expand.vec = call <vscale x 4 x i64> @llvm.masked.expandload(ptr %base, <vscale x 4 x i1> %interleaved.mask, <vscale x 4 x i64> poison)
+ %deinterleaved.vec = call { <vscale x 2 x i64>, <vscale x 2 x i64> } @llvm.vector.deinterleave2.nxv4i64(<vscale x 4 x i64> %wide.expand.vec)
+ ret { <vscale x 2 x i64>, <vscale x 2 x i64> } %deinterleaved.vec
+}
diff --git a/llvm/test/CodeGen/AArch64/scalable_masked_interleaved_stores.ll b/llvm/test/CodeGen/AArch64/scalable_masked_interleaved_stores.ll
index 766777925e909..03904fbd489fd 100644
--- a/llvm/test/CodeGen/AArch64/scalable_masked_interleaved_stores.ll
+++ b/llvm/test/CodeGen/AArch64/scalable_masked_interleaved_stores.ll
@@ -1,6 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
-; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s
-; RUN: llc -mtriple=aarch64-linux-gnu -lower-interleaved-accesses=false -mattr=+sve < %s | FileCheck %s
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve2p2 < %s | FileCheck %s
+; RUN: llc -mtriple=aarch64-linux-gnu -lower-interleaved-accesses=false -mattr=+sve2p2 < %s | FileCheck %s
define void @foo_st2_nxv16i8(<vscale x 16 x i1> %mask, <vscale x 16 x i8> %val1, <vscale x 16 x i8> %val2, ptr %p) {
; CHECK-LABEL: foo_st2_nxv16i8:
@@ -395,3 +395,26 @@ define void @foo_st4_nxv16i8_splat(<vscale x 16 x i1> %mask, ptr %p) {
call void @llvm.masked.store.nxv64i8.p0(<vscale x 64 x i8> %interleaved.value, ptr %p, i32 1, <vscale x 64 x i1> %interleaved.mask)
ret void
}
+
+; Negative test: A compressstore cannot be folded with a vector interleave into a st2.
+define void @do_not_fold_compressstore_interleave(<vscale x 2 x i1> %mask, <vscale x 2 x i64> %val1, <vscale x 2 x i64> %val2, ptr %p) {
+; CHECK-LABEL: do_not_fold_compressstore_interleave:
+; CHECK: // %bb.0:
+; CHECK-NEXT: zip2 p1.d, p0.d, p0.d
+; CHECK-NEXT: zip2 z2.d, z0.d, z1.d
+; CHECK-NEXT: zip1 z0.d, z0.d, z1.d
+; CHECK-NEXT: zip1 p0.d, p0.d, p0.d
+; CHECK-NEXT: cntp x8, p1, p1.d
+; CHECK-NEXT: cntp x9, p0, p0.d
+; CHECK-NEXT: compact z1.d, p1, z2.d
+; CHECK-NEXT: compact z0.d, p0, z0.d
+; CHECK-NEXT: whilelo p0.d, xzr, x8
+; CHECK-NEXT: whilelo p1.d, xzr, x9
+; CHECK-NEXT: st1d { z1.d }, p0, [x0, x9, lsl #3]
+; CHECK-NEXT: st1d { z0.d }, p1, [x0]
+; CHECK-NEXT: ret
+ %interleaved.mask = call <vscale x 4 x i1> @llvm.vector.interleave2.nxv4i1(<vscale x 2 x i1> %mask, <vscale x 2 x i1> %mask)
+ %interleaved.value = call <vscale x 4 x i64> @llvm.vector.interleave2.nxv4i64(<vscale x 2 x i64> %val1, <vscale x 2 x i64> %val2)
+ call void @llvm.masked.compressstore.nxv4i64.p0(<vscale x 4 x i64> %interleaved.value, ptr %p, <vscale x 4 x i1> %interleaved.mask)
+ ret void
+}
|
paulwalker-arm
approved these changes
Nov 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously,
performVector(De)interleaveCombinewould miscompile by combining expandloads and compressstores with deinterleaves and interleaves respectively.This is fixed by updating
ISD::isNormalMaskedLoad()andISD::isNormalMaskedStore()to exclude isExpandingLoad() and isCompressingStore().