[llvm] [AArch64] Fix v4i8 loads in strict-align mode. (PR #95828)
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 17 11:56:17 PDT 2024
https://github.com/efriedma-quic created https://github.com/llvm/llvm-project/pull/95828
Fixes #95811
>From c2f06f1a0664c77bdfac5fdf6fec7ec42e953c23 Mon Sep 17 00:00:00 2001
From: Eli Friedman <efriedma at quicinc.com>
Date: Mon, 17 Jun 2024 11:54:06 -0700
Subject: [PATCH] [AArch64] Fix v4i8 loads in strict-align mode.
Fixes #95811
---
.../Target/AArch64/AArch64ISelLowering.cpp | 4 ++
llvm/test/CodeGen/AArch64/aarch64-load-ext.ll | 47 +++++++++++++++++++
2 files changed, 51 insertions(+)
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 360a841bdade4..78fcc0bbad7ca 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -6406,6 +6406,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 945a73b05f1ba..317feb5ad9ad0 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
+}
More information about the llvm-commits
mailing list