[all-commits] [llvm/llvm-project] 03de1c: [InstCombine][CGP] Move swapMayExposeCSEOpportunit...

Nikita Popov via All-commits all-commits at lists.llvm.org
Thu Jun 15 05:18:17 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 03de1cb715c9a106f3ea4139042a33afcd7ca6ae
      https://github.com/llvm/llvm-project/commit/03de1cb715c9a106f3ea4139042a33afcd7ca6ae
  Author: Nikita Popov <npopov at redhat.com>
  Date:   2023-06-15 (Thu, 15 Jun 2023)

  Changed paths:
    M llvm/lib/CodeGen/CodeGenPrepare.cpp
    M llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
    M llvm/test/CodeGen/Lanai/sub-cmp-peephole.ll
    M llvm/test/CodeGen/RISCV/aext-to-sext.ll
    M llvm/test/CodeGen/Thumb2/LowOverheadLoops/varying-outer-2d-reduction.ll
    M llvm/test/CodeGen/Thumb2/mve-postinc-lsr.ll
    M llvm/test/CodeGen/X86/cmp-merge.ll
    M llvm/test/CodeGen/X86/jump_sign.ll
    M llvm/test/Transforms/InstCombine/abs-intrinsic.ll
    M llvm/test/Transforms/InstCombine/icmp.ll
    M llvm/test/Transforms/InstCombine/result-of-usub-is-non-zero-and-no-overflow.ll
    M llvm/test/Transforms/InstCombine/strict-sub-underflow-check-to-comparison-of-sub-operands.ll
    M llvm/test/Transforms/InstCombine/sub-ashr-or-to-icmp-select.ll
    M llvm/test/Transforms/InstCombine/unsigned-sub-lack-of-overflow-check.ll
    M llvm/test/Transforms/InstCombine/unsigned-sub-overflow-check.ll

  Log Message:
  -----------
  [InstCombine][CGP] Move swapMayExposeCSEOpportunities() fold

InstCombine tries to swap compare operands to match sub instructions
in order to expose "CSE opportunities". However, it doesn't really
make sense to perform this transform in the middle-end, as we cannot
actually CSE the instructions there.

The backend already performs this fold in
https://github.com/llvm/llvm-project/blob/18f5446a45da5a61dbfb1b7667d27fb441ac62db/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp#L4236
on the SDAG level, however this only works within a single basic block.

To handle cross-BB cases, we do need to handle this in the IR layer.
This patch moves the fold from InstCombine to CGP in the backend,
while keeping the same (somewhat dubious) heuristic.

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




More information about the All-commits mailing list