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 | This is a set, so it's slightly misleading to call it list. CommutedInsts would be better | |
| 239–244 | Why not reorder this so the operand check is done before commuting the first time? | |
| 248 | Why do you need to track the instructions? Can you just add whether the instruction needs commuting to the FoldCandidate? | |
| 527–535 | 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 | You can just use the simple form of commuteInstruction which calls findCommutedOpIndices for you | |
| lib/Target/AMDGPU/SIFoldOperands.cpp | ||
|---|---|---|
| 239–249 | This is still undoing the commute, I meant to move the operand legal check before the first commuteInstruction. | |
| lib/Target/AMDGPU/SIFoldOperands.cpp | ||
|---|---|---|
| 76 | The whole set is removed. | |
| 239–244 | isOperandLegal walks actual operands, it may return wrong value if called on an instruction before commuted. | |
| 239–249 | It will not work: isOperandLegal walks actual operands, it may return wrong value if called on an instruction before commuted. | |
| 527–535 | Oops. Leftover from earlier attempts. | |
LGTM
| lib/Target/AMDGPU/SIFoldOperands.cpp | ||
|---|---|---|
| 723 | Should add a comment that this is undoing the commute if the fold failed to restore the instruction to its original order | |
This is a set, so it's slightly misleading to call it list. CommutedInsts would be better