This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Preserve operand order in SIFoldOperands
ClosedPublic

Authored by rampitec on Jun 1 2017, 2:33 PM.

Details

Summary

SIFoldOperands can commute operands even if no folding was done.
This change is to preserve IR is no folding was done.

Diff Detail

Repository
rL LLVM

Event Timeline

rampitec created this revision.Jun 1 2017, 2:33 PM
arsenm edited edge metadata.Jun 1 2017, 2:50 PM

It would make sense to compute even if nothing is folded, since having constants in src0 as the canonical order would make sense, although I think it blindly commutes still as it is

lib/Target/AMDGPU/SIFoldOperands.cpp
76 ↗(On Diff #101115)

This is a set, so it's slightly misleading to call it list. CommutedInsts would be better

239–244 ↗(On Diff #101115)

Why not reorder this so the operand check is done before commuting the first time?

248 ↗(On Diff #101115)

Why do you need to track the instructions? Can you just add whether the instruction needs commuting to the FoldCandidate?

527–535 ↗(On Diff #101115)

Why is changing the constant folding necessary? Nothing is actually commuted here, the instruction isn't mutated. This only does anything if the instruction is being replaced with another instruction anyway.

723–726 ↗(On Diff #101115)

You can just use the simple form of commuteInstruction which calls findCommutedOpIndices for you

It would make sense to compute even if nothing is folded, since having constants in src0 as the canonical order would make sense, although I think it blindly commutes still as it is

It now blindly commutes everything.

rampitec updated this revision to Diff 101126.Jun 1 2017, 3:28 PM
rampitec marked 4 inline comments as done.

Addressed review comments.

arsenm added inline comments.Jun 2 2017, 1:38 PM
lib/Target/AMDGPU/SIFoldOperands.cpp
243–251 ↗(On Diff #101126)

This is still undoing the commute, I meant to move the operand legal check before the first commuteInstruction.

rampitec added inline comments.Jun 2 2017, 1:40 PM
lib/Target/AMDGPU/SIFoldOperands.cpp
243–251 ↗(On Diff #101126)

It will not work: isOperandLegal walks actual operands, it may return wrong value if called on an instruction before commuted.

76 ↗(On Diff #101115)

The whole set is removed.

239–244 ↗(On Diff #101115)

isOperandLegal walks actual operands, it may return wrong value if called on an instruction before commuted.

527–535 ↗(On Diff #101115)

Oops. Leftover from earlier attempts.

arsenm accepted this revision.Jun 2 2017, 1:44 PM

LGTM

lib/Target/AMDGPU/SIFoldOperands.cpp
715 ↗(On Diff #101126)

Should add a comment that this is undoing the commute if the fold failed to restore the instruction to its original order

This revision is now accepted and ready to land.Jun 2 2017, 1:44 PM
rampitec updated this revision to Diff 101275.Jun 2 2017, 1:57 PM
rampitec marked an inline comment as done.

Added comment.

This revision was automatically updated to reflect the committed changes.