[llvm] [AArch64][CodeGen] Fix illegal register aliasing bug for mops instrs (PR #88869)
Nashe Mncube via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 16 07:57:39 PDT 2024
https://github.com/nasherm updated https://github.com/llvm/llvm-project/pull/88869
>From 811b98b9c5f3a15ecb4b60a17eca61d851c18652 Mon Sep 17 00:00:00 2001
From: nasmnc01 <nashe.mncube at arm.com>
Date: Tue, 16 Apr 2024 10:34:09 +0100
Subject: [PATCH 1/2] [AArch64][CodeGen] Fix illegal register aliasing bug for
mops instrs
A bug was found where mops instructions were being generated that
aliased the source and size registers. This is unpredictable behaviour.
This patch usess the earlyclobber constraint on the input source register
so that it doesn't alias with the size register. Also a test is introduced
which tests affected instructions can't violate this constraint.
Change-Id: I34debad21fe8a5f6c33e159b43a1e13d092764a0
---
llvm/lib/Target/AArch64/AArch64InstrInfo.td | 2 +-
.../MC/AArch64/armv9.3a-mops-register-aliasing.s | 15 +++++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/MC/AArch64/armv9.3a-mops-register-aliasing.s
diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.td b/llvm/lib/Target/AArch64/AArch64InstrInfo.td
index e1624f70185e1e..3bf90778363c6c 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.td
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.td
@@ -9486,7 +9486,7 @@ let Predicates = [HasMOPS], Defs = [NZCV], Size = 12, mayStore = 1 in {
let mayLoad = 0 in {
def MOPSMemorySetPseudo : Pseudo<(outs GPR64common:$Rd_wb, GPR64:$Rn_wb),
(ins GPR64common:$Rd, GPR64:$Rn, GPR64:$Rm),
- [], "$Rd = $Rd_wb,$Rn = $Rn_wb">, Sched<[]>;
+ [], "$Rd = $Rd_wb,$Rn = $Rn_wb, at earlyclobber $Rn_wb">, Sched<[]>;
}
}
let Predicates = [HasMOPS, HasMTE], Defs = [NZCV], Size = 12, mayLoad = 0, mayStore = 1 in {
diff --git a/llvm/test/MC/AArch64/armv9.3a-mops-register-aliasing.s b/llvm/test/MC/AArch64/armv9.3a-mops-register-aliasing.s
new file mode 100644
index 00000000000000..109b33857a9d2d
--- /dev/null
+++ b/llvm/test/MC/AArch64/armv9.3a-mops-register-aliasing.s
@@ -0,0 +1,15 @@
+// RUN: not llvm-mc -triple aarch64 -mattr=+mops < %s 2>&1 | FileCheck %s
+
+ setp [x0]!, x1!, x1
+ setm [x0]!, x1!, x1
+ sete [x0]!, x1!, x1
+
+// CHECK: error: invalid SET instruction, source and size registers are the same
+// CHECK-NEXT: setp [x0]!, x1!, x1
+// CHECK-NEXT: ^
+// CHECK-NEXT: error: invalid SET instruction, source and size registers are the same
+// CHECK-NEXT: setm [x0]!, x1!, x1
+// CHECK-NEXT: ^
+// CHECK-NEXT: error: invalid SET instruction, source and size registers are the same
+// CHECK-NEXT: sete [x0]!, x1!, x1
+// CHECK-NEXT: ^
>From f6e7f919bbdf715ace387a85faa94e5e459f234d Mon Sep 17 00:00:00 2001
From: nasmnc01 <nashe.mncube at arm.com>
Date: Tue, 16 Apr 2024 15:56:16 +0100
Subject: [PATCH 2/2] Adding mops intrinsic register alias test
Change-Id: Ifc34f656cc4fb33ad8a46ea80b4896f8d0f2ac60
---
llvm/test/CodeGen/AArch64/mops-register-alias.ll | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
create mode 100644 llvm/test/CodeGen/AArch64/mops-register-alias.ll
diff --git a/llvm/test/CodeGen/AArch64/mops-register-alias.ll b/llvm/test/CodeGen/AArch64/mops-register-alias.ll
new file mode 100644
index 00000000000000..0374c2cea6bc40
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/mops-register-alias.ll
@@ -0,0 +1,16 @@
+; RUN: llc -O1 -mtriple=aarch64-none-linux-gnu -mattr=+mops < %s | FileCheck %s
+
+define void @call_memset_intrinsic() #0 {
+entry:
+ ; CHECK: setp [x8]!, x10!, x9
+ ; CHECK: setm [x8]!, x10!, x9
+ ; CHECK: sete [x8]!, x10!, x9
+
+ %V0 = alloca [65 x i8], align 1
+ call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(64) %V0, i8 64, i64 64, i1 false)
+ %add.ptr = getelementptr inbounds i8, ptr %V0, i64 64
+ call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(64) %add.ptr, i8 64, i64 64, i1 false)
+ ret void
+}
+
+attributes #0 = { "target-cpu"="generic" "target-features"="+mops,+strict-align,+v9.3a" }
More information about the llvm-commits
mailing list