When narrowing a scalar G_EXTRACT where the destination lines up perfectly with a single result of the emitted G_UNMERGE_VALUES a COPY should be emitted instead of unconditionally trying to emit a G_MERGE_VALUES.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp | ||
---|---|---|
3688–3694 | Could this just write the original result into DstReg and avoid the copy? |
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp | ||
---|---|---|
3688–3694 | Hm, the only thing we could reasonably do here to avoid the copy is to change the operand of the defining instruction of DstRegs[0]. The code for this would look something like this: else { MachineInstr *DefInst = MRI.getVRegDef(DstRegs[0]); assert(DefInst && "DstRegs[0] should have been defined"); unsigned Idx = DefInst->getOpcode() == TargetOpcode::G_UNMERGE_VALUES ? OpStart / NarrowSize : 0; DefInst->getOperand(Idx).setReg(DstReg); } I mean it avoids the copy I guess, but not sure if that is really better here? I also tried to rewrite the code to just use DstReg where we want to have it in the first place, but that just clutters the code with if-checks, so also not really nice. Let me know what you think. |
I don't really love extra copies, especially since nothing is trying to get rid of them during legalization but it's not really important
Could this just write the original result into DstReg and avoid the copy?