[llvm] [MachineLICM] Rematerialize instructions that may be hoisted before LICM (PR #158479)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 15 06:56:15 PDT 2025
sharkautarch wrote:
@dianqk
following up on my previous comment (https://github.com/llvm/llvm-project/pull/158479#issuecomment-3289693202)
In your specific testcase from the aforementioned issue, it seems like those hoisted adds had two defs:
- one explicit def: dst register
- one implicit def: eflags register
It seems that in this case, the eflags register isn't actually used by anything
Which makes me wonder if it'd be better to open a new PR which patches the
`if (I.getNumDefs() > 1)` for the AggressiveCycleSink code, to, in the case where `I.getNumDefs()` > 1:
- check if there's only one *explicit* def and if so, if all implicit defs are just on `$eflags` (early exit if either condition is false)
- treat instruction `I` as only having one def (meaning, proceed to sink instruction `I`) if the implicit `$eflags` def isn't actually used by any instruction proceeding instruction `I`
That should allow `-mllvm -sink-insts-to-avoid-spills=1` to handle *most* instructions hoisted by the middle end licm
(and that should still handle most selects, since most selects should be lowered to a `test` or `cmp` x86 insn followed by `cmovCC`, since the `test` and `cmp` insns should only have an `eflags` def)
I would imagine that the only otherwise sinkable insns that would still otherwise be able to be handled by `AggressiveCycleSink` would be arithmetic insns where the eflags def is not used by any `JCC`, but is used by one or more `cmovCC`/`setCC`/`sbb`/etc, likely in the same BB the arithmetic insn is in.
I would reckon that the easiest to handle would be arithmetic insn + `setCC`, whereas w/ `cmovCC` & `sbb` would require you to additionally consider the src def(s) of the `cmovCC`/`sbb` insn(s).
Either way, I definitely think it'd be best to first create a PR that just handles the simpler case of arithmetic insns w/ one explicit def & one `$eflags` def, whose output `$eflags` def isn't used by any following insn.
https://github.com/llvm/llvm-project/pull/158479
More information about the llvm-commits
mailing list