[all-commits] [llvm/llvm-project] 3686a0: [GlobalISel] LegalizationArtifactCombiner: Elide r...

Tobias Stadler via All-commits all-commits at lists.llvm.org
Thu Sep 28 17:15:40 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3686a0b611c65f0d7190345b8e3e73cdca9fa657
      https://github.com/llvm/llvm-project/commit/3686a0b611c65f0d7190345b8e3e73cdca9fa657
  Author: Tobias Stadler <mail at stadler-tobias.de>
  Date:   2023-09-29 (Fri, 29 Sep 2023)

  Changed paths:
    M llvm/include/llvm/CodeGen/GlobalISel/GISelKnownBits.h
    M llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
    M llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
    M llvm/lib/CodeGen/GlobalISel/Legalizer.cpp
    M llvm/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-lse2.ll
    M llvm/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-lse2_lse128.ll
    M llvm/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-outline_atomics.ll
    M llvm/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-rcpc.ll
    M llvm/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-rcpc3.ll
    M llvm/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-v8_1a.ll
    M llvm/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-v8a.ll
    M llvm/test/CodeGen/AArch64/GlobalISel/arm64-atomic.ll
    M llvm/test/CodeGen/AArch64/GlobalISel/combine-ext-debugloc.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/combine-sext-debugloc.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/huge-switch.ll
    M llvm/test/CodeGen/AArch64/GlobalISel/invoke-region.ll
    M llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-hoisted-constants.ll
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-add.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-bswap.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-cmp.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-ctlz.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-ctpop.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-cttz.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-div.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-ext-cse.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-ext-csedebug-output.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-ext.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-extracts.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-freeze.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-fshl.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-fshr.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-inserts.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-intrinsic-min-max.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-itofp.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-load-store.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-merge-values.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-mul.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-phi-insertpt-decrement.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-phi.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-ptrtoint.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-rem.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-sadde.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-saddo.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-saddsat.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-select.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-shift.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-simple.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-ssube.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-ssubo.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-ssubsat.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-sub.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-uadd-sat.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-uadde.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-uaddo.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-usub-sat.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-usube.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalize-usubo.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/legalizer-combiner-zext-trunc-crash.mir
    M llvm/test/CodeGen/AArch64/GlobalISel/retry-artifact-combine.mir
    M llvm/test/CodeGen/AArch64/zext.ll
    M llvm/test/CodeGen/AMDGPU/GlobalISel/artifact-combiner-cse-leaves-dead-cast.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/artifact-combiner-unmerge-values.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/artifact-combiner-zext.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/fshl.ll
    M llvm/test/CodeGen/AMDGPU/GlobalISel/fshr.ll
    M llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-load-private.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-add.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-and.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-anyext.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-ashr.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-bitcast.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-bitreverse.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-bswap.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-ctlz-zero-undef.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-ctlz.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-ctpop.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-cttz.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-fabs.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-fadd.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-fcopysign.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-fma.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-fmaxnum.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-fminnum.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-fmul.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-fneg.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-fshl.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-fshr.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-fsub.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-icmp.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-implicit-def.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-insert.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-intrinsic-round.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-llvm.amdgcn.image.store.2d.d16.ll
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-llvm.amdgcn.s.buffer.load.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-load-constant.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-load-flat.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-load-global.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-load-local.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-load-private.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-lshr.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-merge-values.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-or.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-phi.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-ptrmask.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-rotl-rotr.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-saddo.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-saddsat.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-select.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-sext-inreg.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-sext.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-shl.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-shuffle-vector.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-shuffle-vector.s16.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-smulh.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-smulo.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-sshlsat.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-ssubo.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-ssubsat.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-store-global.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-store.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-trunc.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-uaddo.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-uaddsat.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-udiv.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-umax.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-umin.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-umulh.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-umulo.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-unmerge-values.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-urem.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-ushlsat.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-usubo.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-usubsat.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-xor.mir
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-zext.mir
    M llvm/test/CodeGen/ARM/GlobalISel/arm-legalize-fp.mir
    M llvm/test/CodeGen/Mips/GlobalISel/legalizer/add.mir
    M llvm/test/CodeGen/Mips/GlobalISel/legalizer/bitwise.mir
    M llvm/test/CodeGen/Mips/GlobalISel/legalizer/constants.mir
    M llvm/test/CodeGen/Mips/GlobalISel/legalizer/ctlz.mir
    M llvm/test/CodeGen/Mips/GlobalISel/legalizer/cttz.mir
    M llvm/test/CodeGen/Mips/GlobalISel/legalizer/fptosi_and_fptoui.mir
    M llvm/test/CodeGen/Mips/GlobalISel/legalizer/icmp.mir
    M llvm/test/CodeGen/Mips/GlobalISel/legalizer/jump_table_and_brjt.mir
    M llvm/test/CodeGen/Mips/GlobalISel/legalizer/mul.mir
    M llvm/test/CodeGen/Mips/GlobalISel/legalizer/select.mir
    M llvm/test/CodeGen/Mips/GlobalISel/legalizer/sub.mir
    M llvm/test/CodeGen/Mips/GlobalISel/llvm-ir/add.ll
    M llvm/test/CodeGen/Mips/GlobalISel/llvm-ir/bitwise.ll
    M llvm/test/CodeGen/Mips/GlobalISel/llvm-ir/ctlz.ll
    M llvm/test/CodeGen/Mips/GlobalISel/llvm-ir/cttz.ll
    M llvm/test/CodeGen/Mips/GlobalISel/llvm-ir/fptosi_and_fptoui.ll
    M llvm/test/CodeGen/Mips/GlobalISel/llvm-ir/icmp.ll
    M llvm/test/CodeGen/Mips/GlobalISel/llvm-ir/jump_table_and_brjt.ll
    M llvm/test/CodeGen/Mips/GlobalISel/llvm-ir/mul.ll
    M llvm/test/CodeGen/Mips/GlobalISel/llvm-ir/select.ll
    M llvm/test/CodeGen/Mips/GlobalISel/llvm-ir/sitofp_and_uitofp.ll
    M llvm/test/CodeGen/Mips/GlobalISel/llvm-ir/sub.ll
    M llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-abs.mir
    M llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-add.mir
    M llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-ashr.mir
    M llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-icmp.mir
    M llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-lshr.mir
    M llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-mul-ext.mir
    M llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-shl.mir
    M llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-store.mir
    M llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv32/legalize-sub.mir
    M llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-add.mir
    M llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-ashr.mir
    M llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-icmp.mir
    M llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-lshr.mir
    M llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-mul-ext.mir
    M llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-shl.mir
    M llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-store.mir
    M llvm/test/CodeGen/RISCV/GlobalISel/legalizer/rv64/legalize-sub.mir
    M llvm/test/CodeGen/X86/GlobalISel/ashr-scalar.ll
    M llvm/test/CodeGen/X86/GlobalISel/legalize-cmp.mir
    M llvm/test/CodeGen/X86/GlobalISel/legalize-ext-x86-64.mir
    M llvm/test/CodeGen/X86/GlobalISel/legalize-ext.mir
    M llvm/test/CodeGen/X86/GlobalISel/legalize-trailing-zeros-undef.mir
    M llvm/test/CodeGen/X86/GlobalISel/legalize-trailing-zeros.mir
    M llvm/test/CodeGen/X86/GlobalISel/legalize-trunc.mir
    M llvm/test/CodeGen/X86/GlobalISel/lshr-scalar.ll
    M llvm/test/CodeGen/X86/GlobalISel/x86_64-legalize-zext.mir
    M llvm/unittests/CodeGen/GlobalISel/LegalizerTest.cpp

  Log Message:
  -----------
  [GlobalISel] LegalizationArtifactCombiner: Elide redundant G_AND

The legalizer currently generates lots of G_AND artifacts.
For example between boolean uses and defs there is always a G_AND with a mask of 1, but when the target uses ZeroOrOneBooleanContents, this is unnecessary.
Currently these artifacts have to be removed using post-legalize combines.
Omitting these artifacts at their source in the artifact combiner has a few advantages:
- We know that the emitted G_AND is very likely to be useless, so our KnownBits call is likely worth it.
- The G_AND and G_CONSTANT can interrupt e.g. G_UADDE/... sequences generated during legalization of wide adds which makes it harder to detect these sequences in the instruction selector (e.g. useful to prevent unnecessary reloading of AArch64 NZCV register).
- This cleans up a lot of legalizer output and even improves compilation-times.
AArch64 CTMark geomean: `O0` -5.6% size..text; `O0` and `O3` ~-0.9% compilation-time (instruction count).

Since this introduces KnownBits into code-paths used by `O0`, I reduced the default recursion depth.
This doesn't seem to make a difference in CTMark, but should prevent excessive recursive calls in the worst case.

Reviewed By: aemerson

Differential Revision: https://reviews.llvm.org/D159140




More information about the All-commits mailing list