[all-commits] [llvm/llvm-project] 683994: X86InstrInfo: Refactor and cleanup optimizeCompare...

Matthias Braun via All-commits all-commits at lists.llvm.org
Sun Oct 24 16:44:06 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 683994c863b8b8a46372408773e4bd65502c5193
      https://github.com/llvm/llvm-project/commit/683994c863b8b8a46372408773e4bd65502c5193
  Author: Matthias Braun <matthiasb at fb.com>
  Date:   2021-10-24 (Sun, 24 Oct 2021)

  Changed paths:
    M llvm/lib/Target/X86/X86InstrInfo.cpp
    A llvm/test/CodeGen/X86/optimize-compare.mir

  Log Message:
  -----------
  X86InstrInfo: Refactor and cleanup optimizeCompareInstr

This changes the first part of `optimizeCompareInstr` being split into a
loop with a forward scan for cases that re-use zero flags from a
producer in case of compare with zero and a backward scan for finding an
instruction equivalent to a compare.

The code now uses a single backward scan searching for the next
instructions that reads or writes EFLAGS.

Also:
- Add comments giving examples for the 3 cases handled.
- Check `MI` which contains the result of the zero-compare cases,
  instead of re-checking `IsCmpZero`.
- Tweak coding style in some loops.
- Add new MIR based tests that test the optimization in isolation.

This also removes a check for flag readers in situations like this:
```
= SUB32rr %0, %1, implicit-def $eflags
...  we no longer stop when there are $eflag users here
CMP32rr %0, %1   ; will be removed
...
```

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


  Commit: 4b75d674f899fe2fd22ffe2dee849dbdf015fd9c
      https://github.com/llvm/llvm-project/commit/4b75d674f899fe2fd22ffe2dee849dbdf015fd9c
  Author: Matthias Braun <matthiasb at fb.com>
  Date:   2021-10-24 (Sun, 24 Oct 2021)

  Changed paths:
    M llvm/lib/Target/X86/X86InstrInfo.cpp
    M llvm/test/CodeGen/X86/jump_sign.ll
    M llvm/test/CodeGen/X86/optimize-compare.mir

  Log Message:
  -----------
  X86InstrInfo: Look across basic blocks in optimizeCompareInstr

This extends `optimizeCompareInstr` to continue the backwards search
when it reached the beginning of a basic block. If there is a single
predecessor block then we can just continue the search in that block and
mark the EFLAGS register as live-in.

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


  Commit: 19d3bc1e67b0b651e79bd31a1364c4c9dabdfdd3
      https://github.com/llvm/llvm-project/commit/19d3bc1e67b0b651e79bd31a1364c4c9dabdfdd3
  Author: Matthias Braun <matthiasb at fb.com>
  Date:   2021-10-24 (Sun, 24 Oct 2021)

  Changed paths:
    M llvm/test/CodeGen/X86/optimize-compare.mir

  Log Message:
  -----------
  pre-comitting tests for D110865


Compare: https://github.com/llvm/llvm-project/compare/a461fa64bb37...19d3bc1e67b0


More information about the All-commits mailing list