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