Skip to content

[SelectionDAG] Mark frame index as "aliased" at argument copy elison #89712

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

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions llvm/include/llvm/CodeGen/MachineFrameInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,13 @@ class MachineFrameInfo {
return Objects[ObjectIdx+NumFixedObjects].isAliased;
}

/// Set "maybe pointed to by an LLVM IR value" for an object.
void setIsAliasedObjectIndex(int ObjectIdx, bool IsAliased) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void setIsAliasedObjectIndex(int ObjectIdx, bool IsAliased) {
void setIsAliasedObjectIndex(int ObjectIdx, bool IsAliased = true) {

assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
"Invalid Object Idx!");
Objects[ObjectIdx+NumFixedObjects].isAliased = IsAliased;
}

/// Returns true if the specified index corresponds to an immutable object.
bool isImmutableObjectIndex(int ObjectIdx) const {
// Tail calling functions can clobber their function arguments.
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11128,14 +11128,15 @@ static void tryToElideArgumentCopy(
}

// Perform the elision. Delete the old stack object and replace its only use
// in the variable info map. Mark the stack object as mutable.
// in the variable info map. Mark the stack object as mutable and aliased.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any practical difference between the mutable and isAliased cases? Where is the ultimate alias query that goes wrong?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isAliased is used inside ScheduleDAGInstrs.cpp getUnderlyingObjectsForInstr:

      if (const PseudoSourceValue *PSV = MMO->getPseudoValue()) {
        // Function that contain tail calls don't have unique PseudoSourceValue
        // objects. Two PseudoSourceValues might refer to the same or
        // overlapping locations. The client code calling this function assumes
        // this is not the case. So return a conservative answer of no known
        // object.
        if (MFI.hasTailCall())
          return false;

        // For now, ignore PseudoSourceValues which may alias LLVM IR values
        // because the code that uses this function has no way to cope with
        // such aliases.
        if (PSV->isAliased(&MFI))
          return false;

        bool MayAlias = PSV->mayAlias(&MFI);
        Objects.emplace_back(PSV, MayAlias);
      } else if (const Value *V = MMO->getValue()) {

LLVM_DEBUG({
dbgs() << "Eliding argument copy from " << Arg << " to " << *AI << '\n'
<< " Replacing frame index " << OldIndex << " with " << FixedIndex
<< '\n';
});
MFI.RemoveStackObject(OldIndex);
MFI.setIsImmutableObjectIndex(FixedIndex, false);
MFI.setIsAliasedObjectIndex(FixedIndex, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MFI.setIsAliasedObjectIndex(FixedIndex, true);
MFI.setIsAliasedObjectIndex(FixedIndex);

AllocaIndex = FixedIndex;
ArgCopyElisionFrameIndexMap.insert({OldIndex, FixedIndex});
for (SDValue ArgVal : ArgVals)
Expand Down
6 changes: 2 additions & 4 deletions llvm/test/CodeGen/Hexagon/arg-copy-elison.ll
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ define i32 @f(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i
; CHECK-NEXT: // %bb.0:
; CHECK-NEXT: {
; CHECK-NEXT: r0 = memw(r29+#36)
; CHECK-NEXT: memw(r29+#32) = ##666
; CHECK-NEXT: }
; CHECK-NEXT: {
; CHECK-NEXT: r1 = memw(r29+#28)
; CHECK-NEXT: r2 = memw(r29+#32)
; CHECK-NEXT: }
; CHECK-NEXT: {
; CHECK-NEXT: r0 = sub(r1,r0)
; CHECK-NEXT: r2 = memw(r29+#32)
; CHECK-NEXT: memw(r29+#32) = ##666
; CHECK-NEXT: }
; CHECK-NEXT: {
; CHECK-NEXT: r0 = xor(r0,r2)
Expand Down
Loading