[clang] [CodeGen] Emit a more accurate alignment for non-temporal loads/stores (PR #75675)
Akira Hatanaka via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 15 16:35:40 PST 2023
https://github.com/ahatanak created https://github.com/llvm/llvm-project/pull/75675
Call EmitPointerWithAlignment to compute the alignment based on the underlying lvalue's alignment when it's available.
>From 641aba730a38038da0d5a9ef8a56fab908131144 Mon Sep 17 00:00:00 2001
From: Akira Hatanaka <ahatanak at gmail.com>
Date: Fri, 15 Dec 2023 15:52:39 -0800
Subject: [PATCH] [CodeGen] Emit a more accurate alignment for non-temporal
loads/stores
Call EmitPointerWithAlignment to compute the alignment based on the
underlying lvalue's alignment when it's available.
---
clang/lib/CodeGen/CGBuiltin.cpp | 8 ++++----
clang/test/CodeGen/Nontemporal.cpp | 14 ++++++++++++++
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 3327866d2b9623..c96f86a823a461 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -232,19 +232,19 @@ static Value *MakeBinaryAtomicValue(
static Value *EmitNontemporalStore(CodeGenFunction &CGF, const CallExpr *E) {
Value *Val = CGF.EmitScalarExpr(E->getArg(0));
- Value *Address = CGF.EmitScalarExpr(E->getArg(1));
+ Address Addr = CGF.EmitPointerWithAlignment(E->getArg(1));
Val = CGF.EmitToMemory(Val, E->getArg(0)->getType());
- LValue LV = CGF.MakeNaturalAlignAddrLValue(Address, E->getArg(0)->getType());
+ LValue LV = CGF.MakeAddrLValue(Addr, E->getArg(0)->getType());
LV.setNontemporal(true);
CGF.EmitStoreOfScalar(Val, LV, false);
return nullptr;
}
static Value *EmitNontemporalLoad(CodeGenFunction &CGF, const CallExpr *E) {
- Value *Address = CGF.EmitScalarExpr(E->getArg(0));
+ Address Addr = CGF.EmitPointerWithAlignment(E->getArg(0));
- LValue LV = CGF.MakeNaturalAlignAddrLValue(Address, E->getType());
+ LValue LV = CGF.MakeAddrLValue(Addr, E->getType());
LV.setNontemporal(true);
return CGF.EmitLoadOfScalar(LV, E->getExprLoc());
}
diff --git a/clang/test/CodeGen/Nontemporal.cpp b/clang/test/CodeGen/Nontemporal.cpp
index e14ca18717928d..5052cb225d4111 100644
--- a/clang/test/CodeGen/Nontemporal.cpp
+++ b/clang/test/CodeGen/Nontemporal.cpp
@@ -46,3 +46,17 @@ void test_all_sizes(void) // CHECK-LABEL: test_all_sizes
vf2 = __builtin_nontemporal_load(&vf1); // CHECK: load <4 x float>{{.*}}align 16, !nontemporal
vc2 = __builtin_nontemporal_load(&vc1); // CHECK: load <8 x i8>{{.*}}align 8, !nontemporal
}
+
+struct S { char c[16]; };
+S x;
+
+typedef int v4si __attribute__ ((vector_size(16)));
+
+// CHECK-LABEL: define void @_Z14test_alignmentv()
+// CHECK: load <4 x i32>, ptr @x, align 1, !nontemporal
+// CHECK: store <4 x i32> %1, ptr @x, align 1, !nontemporal
+
+void test_alignment() {
+ auto t = __builtin_nontemporal_load((v4si*)x.c);
+ __builtin_nontemporal_store(t, (v4si*)x.c);
+}
More information about the cfe-commits
mailing list