[llvm] [GISel] LegalizationArtifactCombiner: Elide redundant G_SEXT_INREG (PR #93687)
Amara Emerson via llvm-commits
llvm-commits at lists.llvm.org
Wed May 29 21:59:07 PDT 2024
aemerson wrote:
> The justification is just the same. This eliminates redundant instructions after each instruction producing a boolean value (comparisons and long arithmetic). I though it is artifact combiner's job to eliminate the redundant extensions/truncations inserted by the legalizer. Is it not?
The real reason the artifact combiner is there is because it's actually required in order for our legalization algorithm to terminate. We need to elide unlegalizable artifacts that cancel out in order for it to work at all. Other combines just tag along and we should be careful about adding new ones. That said, if this is purely a mirror for the G_AND one for other boolean format targets then I think it's ok.
>
> I don't have large benchmarks, but on what I have, this patch gives ~1.0% compile time speedup at -O0 and ~1.6% speedup at -O2. .text size is reduced by 2% to 4% depending on optimization level (there _is_ a difference even at -O2 because shl + ashr pair is not currently optimized by the generic combiner).
>
> I didn't measure targets with zero-or-one booleans, but I don't expect the compile time to increase perceptibly because trunc+sext pair is much less likely to occur for them at legalization time. I did run `time ninja check-llvm-codegen-amdgpu-globalisel` though (a target with 776 G_SEXT_INREG in GlobalISel tests), and there was no difference in testing time. It might be worth noting that a call to KnownBits is limited by Depth == 2 at -O0.
https://github.com/llvm/llvm-project/pull/93687
More information about the llvm-commits
mailing list