-
Notifications
You must be signed in to change notification settings - Fork 15.1k
CodeGen: More accurate mayAlias for instructions with multiple MMOs #166211
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
Conversation
|
@llvm/pr-subscribers-backend-systemz Author: Nicolai Hähnle (nhaehnle) ChangesThere can only be meaningful aliasing between the memory accesses of This check is applied at the instruction-level earlier in the method. This affects a SystemZ test because PFD instructions are both mayLoad Stack:
Full diff: https://github.com/llvm/llvm-project/pull/166211.diff 2 Files Affected:
diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp
index 8ad9245a47684..37e5c517d24d8 100644
--- a/llvm/lib/CodeGen/MachineInstr.cpp
+++ b/llvm/lib/CodeGen/MachineInstr.cpp
@@ -1547,10 +1547,14 @@ bool MachineInstr::mayAlias(BatchAAResults *AA, const MachineInstr &Other,
// Check each pair of memory operands from both instructions, which can't
// alias only if all pairs won't alias.
- for (auto *MMOa : memoperands())
- for (auto *MMOb : Other.memoperands())
+ for (auto *MMOa : memoperands()) {
+ for (auto *MMOb : Other.memoperands()) {
+ if (!MMOa->isStore() && !MMOb->isStore())
+ continue;
if (MemOperandsHaveAlias(MFI, AA, UseTBAA, MMOa, MMOb))
return true;
+ }
+ }
return false;
}
diff --git a/llvm/test/CodeGen/SystemZ/vec-load-element.ll b/llvm/test/CodeGen/SystemZ/vec-load-element.ll
index 2baaed19546df..9bef279d7c0fa 100644
--- a/llvm/test/CodeGen/SystemZ/vec-load-element.ll
+++ b/llvm/test/CodeGen/SystemZ/vec-load-element.ll
@@ -5,8 +5,8 @@
; CHECK-LABEL: .LBB0_1:
; CHECK-NOT: l %r
; CHECK-NOT: vlvgf
-; CHECK: pfd
-; CHECK: vlef
+; CHECK-DAG: pfd
+; CHECK-DAG: vlef
%type0 = type { i32, [400 x i8], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
@Mem = external global [150 x %type0], align 4
|
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.
This patch highlights a problem that I have run into before: if we want to support a single opcode (in this case BUNDLE) that may or may not load or store depending on its operands, then the current definitions of MachineInstr::mayLoad and mayStore are not good enough, because they just check a static property of the opcode.
If mayLoad and mayStore were more sophisticated then this check would have been handled already at L1527.
Having said that, in the short term I have no objection to this patch.
e64b325 to
c3abece
Compare
A potential solution to this problem would be an empty MMO, i.e. an MMO that can never alias anything.
This change aims at something subtly different. What it aims to do is improve the alias checking of two instructions with MMOs:
These two instructions don't alias, since their only overlap is in the load MMOs, which isn't a conflict. |
c3abece to
0470587
Compare
764dc17 to
fe082d1
Compare
0470587 to
f40a20f
Compare
fe082d1 to
e59b115
Compare
Yeah, I realized that later. LGTM. |
There can only be meaningful aliasing between the memory accesses of different instructions if at least one of the accesses modifies memory. This check is applied at the instruction-level earlier in the method. This change merely extends the check on a per-MMO basis. This affects a SystemZ test because PFD instructions are both mayLoad and mayStore but may carry a load-only MMO which is now no longer treated as aliasing loads. The PFD instructions are from llvm.prefetch generated by loop-data-prefetch. commit-id:667859fc
f40a20f to
4e20232
Compare
|
The Windows CI reports a failure, but the logs look completely clean except for this error that seems to originate from the CI infra itself: |
There can only be meaningful aliasing between the memory accesses of
different instructions if at least one of the accesses modifies memory.
This check is applied at the instruction-level earlier in the method.
This change merely extends the check on a per-MMO basis.
This affects a SystemZ test because PFD instructions are both mayLoad
and mayStore but may carry a load-only MMO which is now no longer
treated as aliasing loads. The PFD instructions are from llvm.prefetch
generated by loop-data-prefetch.
Stack: