SIFoldOperands can commute operands even if no folding was done.
This change is to preserve IR is no folding was done.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
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 |
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. |
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. |
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 |