[llvm] [GISel] LegalizationArtifactCombiner: Elide redundant G_SEXT_INREG (PR #93687)

Sergei Barannikov via llvm-commits llvm-commits at lists.llvm.org
Wed May 29 10:48:36 PDT 2024


s-barannikov 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?

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