[llvm] [GlobalISel] Fold G_ICMP if possible (PR #86357)

Amara Emerson via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 28 09:54:15 PDT 2024


aemerson wrote:

> @aemerson @arsenm I think we should really avoid using a defined register as destination operand for other new instructions. This basically breaks the SSA rule. If there is no constant folding when building a new instruction between the two same definitions, it doesn't have any issue **so far**. People will be likely to run into a similar issue as here in the future if they want to add new constant folding. In the combiner, most of the functions define a new vreg for the destination, and then replace the original one with the new one. The replacement, depending on the original register, could be a `G_COPY`, like what we are doing here. In fact, the build of `G_COPY` kinda also breaks the SSA rule because it uses a defined register as destination. I think that should be the only exception, and there should not be any other kind of new instructions built between this point and the erase of the original instruction. Interestingly, it may not always work if we erase the original instruction first and then build others because the builder will complain that the insert point is out of the basic block.

This sounds reasonable to me but I don't think we should enforce that everywhere, because we use defined regs in the instruction selector pass. In AArch64 we often use MachineIRBuilder's `buildInstr()`, the non-CSE version that is, to easily generate target specific instructions. 

https://github.com/llvm/llvm-project/pull/86357


More information about the llvm-commits mailing list