-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AArch64][CodeGen] Fix illegal register aliasing bug for mops instrs #88869
Conversation
@llvm/pr-subscribers-backend-aarch64 @llvm/pr-subscribers-mc Author: Nashe Mncube (nasherm) ChangesA 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. Full diff: https://github.com/llvm/llvm-project/pull/88869.diff 2 Files Affected:
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,@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: ^
|
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any LLVM IR tests that can be added for this? As this is a CodeGen issue we should add these.
Is the |
I think there should also be some LLVM-Lit tests that check the IR CodeGen. The llvm-mc test checks any assembly which the user inputs into the compiler, but if an ACLE Intrinsic is used this can be checked differently within the tests. The tests can be written in a way that the output is check not to be a certain value/register. See #77770 for an example of how a test can ensure early-clobber was being respected within IR and CodeGen. |
69bb2db
to
b60f15c
Compare
Change-Id: Ifc34f656cc4fb33ad8a46ea80b4896f8d0f2ac60
Change-Id: I68edcdf4414d8a21b2267e7593997f0276ad6e54
I've written an IR test and updated the PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more comment from me.
Approved - But worth getting a 2nd set of eyes over it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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.