X86InstrInfo: Support immediates that are +1/-1 different in optimizeCompareInstr
authorMatthias Braun <matthiasb@fb.com>
Tue, 28 Sep 2021 00:57:22 +0000 (17:57 -0700)
committerMatthias Braun <matthiasb@fb.com>
Thu, 28 Oct 2021 17:33:56 +0000 (10:33 -0700)
commite2c7ee0743592e39274e28dbe0d0c213ba342317
treefdd0059b62ab09fe7a1480a16ceac32a2fc6bdd8
parent97a1570d8c31dc3bff12dd77b1ee824e1872bb69
X86InstrInfo: Support immediates that are +1/-1 different in optimizeCompareInstr

This extends `optimizeCompareInstr` to re-use previous comparison
results if the previous comparison was with an immediate that was 1
bigger or smaller. Example:

    CMP x, 13
    ...
    CMP x, 12   ; can be removed if we change the SETg
    SETg ...    ; x > 12  changed to `SETge` (x >= 13) removing CMP

Motivation: This often happens because SelectionDAG canonicalization
tends to add/subtract 1 often when optimizing for fallthrough blocks.
Example for `x > C` the fallthrough optimization switches true/false
blocks with `!(x > C)` --> `x <= C` and canonicalization turns this into
`x < C + 1`.

Differential Revision: https://reviews.llvm.org/D110867
llvm/lib/Target/X86/X86InstrInfo.cpp
llvm/lib/Target/X86/X86InstrInfo.h
llvm/test/CodeGen/X86/optimize-compare.mir
llvm/test/CodeGen/X86/peep-test-5.ll [new file with mode: 0644]
llvm/test/CodeGen/X86/use-cr-result-of-dom-icmp-st.ll