diff options
author | Eli Friedman <efriedma@quicinc.com> | 2024-06-18 10:12:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-18 10:12:07 -0700 |
commit | 8570685d3b5a71d9a65a8c37a88fb0184d9b131c (patch) | |
tree | b3d06a7aaf7405d06c3b7d1195b0bdee4c3db388 | |
parent | 5207632f8698a2fab0c4cdcdf2f7ad9aaf96e06f (diff) | |
download | llvm-8570685d3b5a71d9a65a8c37a88fb0184d9b131c.zip llvm-8570685d3b5a71d9a65a8c37a88fb0184d9b131c.tar.gz llvm-8570685d3b5a71d9a65a8c37a88fb0184d9b131c.tar.bz2 |
[AArch64] Fix v4i8 loads in strict-align mode. (#95828)
Fixes #95811
-rw-r--r-- | llvm/lib/Target/AArch64/AArch64ISelLowering.cpp | 4 | ||||
-rw-r--r-- | llvm/test/CodeGen/AArch64/aarch64-load-ext.ll | 47 |
2 files changed, 51 insertions, 0 deletions
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp index 07a47e9..9f6f66e 100644 --- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -6491,6 +6491,10 @@ SDValue AArch64TargetLowering::LowerLOAD(SDValue Op, if (LoadNode->getMemoryVT() != MVT::v4i8) return SDValue(); + // Avoid generating unaligned loads. + if (Subtarget->requiresStrictAlign() && LoadNode->getAlign() < Align(4)) + return SDValue(); + unsigned ExtType; if (LoadNode->getExtensionType() == ISD::SEXTLOAD) ExtType = ISD::SIGN_EXTEND; diff --git a/llvm/test/CodeGen/AArch64/aarch64-load-ext.ll b/llvm/test/CodeGen/AArch64/aarch64-load-ext.ll index 945a73b..317feb5 100644 --- a/llvm/test/CodeGen/AArch64/aarch64-load-ext.ll +++ b/llvm/test/CodeGen/AArch64/aarch64-load-ext.ll @@ -450,3 +450,50 @@ define <4 x i8> @bitcast(i32 %0) { %2 = bitcast i32 %0 to <4 x i8> ret <4 x i8> %2 } + +define <4 x i8> @strict_align_aligned(ptr %v4i8_ptr) "target-features"="+strict-align" { +; CHECK-LE-LABEL: strict_align_aligned: +; CHECK-LE: // %bb.0: +; CHECK-LE-NEXT: ldr s0, [x0] +; CHECK-LE-NEXT: ushll v0.8h, v0.8b, #0 +; CHECK-LE-NEXT: // kill: def $d0 killed $d0 killed $q0 +; CHECK-LE-NEXT: ret +; +; CHECK-BE-LABEL: strict_align_aligned: +; CHECK-BE: // %bb.0: +; CHECK-BE-NEXT: ldr s0, [x0] +; CHECK-BE-NEXT: rev32 v0.8b, v0.8b +; CHECK-BE-NEXT: ushll v0.8h, v0.8b, #0 +; CHECK-BE-NEXT: rev64 v0.4h, v0.4h +; CHECK-BE-NEXT: ret + %v4i8 = load <4 x i8>, ptr %v4i8_ptr, align 4 + ret <4 x i8> %v4i8 +} + +define <4 x i8> @strict_align_unaligned(ptr %v4i8_ptr) "target-features"="+strict-align" { +; CHECK-LE-LABEL: strict_align_unaligned: +; CHECK-LE: // %bb.0: +; CHECK-LE-NEXT: ld1 { v0.b }[0], [x0] +; CHECK-LE-NEXT: add x8, x0, #1 +; CHECK-LE-NEXT: ld1 { v0.b }[2], [x8] +; CHECK-LE-NEXT: add x8, x0, #2 +; CHECK-LE-NEXT: ld1 { v0.b }[4], [x8] +; CHECK-LE-NEXT: add x8, x0, #3 +; CHECK-LE-NEXT: ld1 { v0.b }[6], [x8] +; CHECK-LE-NEXT: // kill: def $d0 killed $d0 killed $q0 +; CHECK-LE-NEXT: ret +; +; CHECK-BE-LABEL: strict_align_unaligned: +; CHECK-BE: // %bb.0: +; CHECK-BE-NEXT: ld1 { v0.b }[0], [x0] +; CHECK-BE-NEXT: add x8, x0, #1 +; CHECK-BE-NEXT: ld1 { v0.b }[2], [x8] +; CHECK-BE-NEXT: add x8, x0, #2 +; CHECK-BE-NEXT: ld1 { v0.b }[4], [x8] +; CHECK-BE-NEXT: add x8, x0, #3 +; CHECK-BE-NEXT: ld1 { v0.b }[6], [x8] +; CHECK-BE-NEXT: rev64 v0.4h, v0.4h +; CHECK-BE-NEXT: ret + %v4i8 = load <4 x i8>, ptr %v4i8_ptr, align 1 + ret <4 x i8> %v4i8 +} |