Skip to content

Commit 70a9448

Browse files
committed
[SelectionDAG] Mark frame index as "aliased" at argument copy elison
This is a fix for miscompiles reported in #89060 After argument copy elison the IR value for the eliminated alloca is aliasing with the fixed stack object. This patch is making sure that we mark the fixed stack object as being aliased with IR values to avoid that for example schedulers are reordering accesses to the fixed stack object. This could otherwise happen when there is a mix of MemOperands refering the shared fixed stack slow via both the IR value for the elided alloca, and via a fixed stack pseudo source value (as would be the case when lowering the arguments).
1 parent 55c971b commit 70a9448

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

llvm/include/llvm/CodeGen/MachineFrameInfo.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,13 @@ class MachineFrameInfo {
701701
return Objects[ObjectIdx+NumFixedObjects].isAliased;
702702
}
703703

704+
/// Set "maybe pointed to by an LLVM IR value" for an object.
705+
void setIsAliasedObjectIndex(int ObjectIdx, bool IsAliased) {
706+
assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
707+
"Invalid Object Idx!");
708+
Objects[ObjectIdx+NumFixedObjects].isAliased = IsAliased;
709+
}
710+
704711
/// Returns true if the specified index corresponds to an immutable object.
705712
bool isImmutableObjectIndex(int ObjectIdx) const {
706713
// Tail calling functions can clobber their function arguments.

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11128,14 +11128,15 @@ static void tryToElideArgumentCopy(
1112811128
}
1112911129

1113011130
// Perform the elision. Delete the old stack object and replace its only use
11131-
// in the variable info map. Mark the stack object as mutable.
11131+
// in the variable info map. Mark the stack object as mutable and aliased.
1113211132
LLVM_DEBUG({
1113311133
dbgs() << "Eliding argument copy from " << Arg << " to " << *AI << '\n'
1113411134
<< " Replacing frame index " << OldIndex << " with " << FixedIndex
1113511135
<< '\n';
1113611136
});
1113711137
MFI.RemoveStackObject(OldIndex);
1113811138
MFI.setIsImmutableObjectIndex(FixedIndex, false);
11139+
MFI.setIsAliasedObjectIndex(FixedIndex, true);
1113911140
AllocaIndex = FixedIndex;
1114011141
ArgCopyElisionFrameIndexMap.insert({OldIndex, FixedIndex});
1114111142
for (SDValue ArgVal : ArgVals)

llvm/test/CodeGen/Hexagon/arg-copy-elison.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ define i32 @f(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i
1818
; CHECK-NEXT: // %bb.0:
1919
; CHECK-NEXT: {
2020
; CHECK-NEXT: r0 = memw(r29+#36)
21-
; CHECK-NEXT: memw(r29+#32) = ##666
22-
; CHECK-NEXT: }
23-
; CHECK-NEXT: {
2421
; CHECK-NEXT: r1 = memw(r29+#28)
25-
; CHECK-NEXT: r2 = memw(r29+#32)
2622
; CHECK-NEXT: }
2723
; CHECK-NEXT: {
2824
; CHECK-NEXT: r0 = sub(r1,r0)
25+
; CHECK-NEXT: r2 = memw(r29+#32)
26+
; CHECK-NEXT: memw(r29+#32) = ##666
2927
; CHECK-NEXT: }
3028
; CHECK-NEXT: {
3129
; CHECK-NEXT: r0 = xor(r0,r2)

0 commit comments

Comments
 (0)