[all-commits] [llvm/llvm-project] 97a157: X86InstrInfo: Optimize more combinations of SUB+CMP
Matthias Braun via All-commits
all-commits at lists.llvm.org
Thu Oct 28 10:34:26 PDT 2021
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 97a1570d8c31dc3bff12dd77b1ee824e1872bb69
https://github.com/llvm/llvm-project/commit/97a1570d8c31dc3bff12dd77b1ee824e1872bb69
Author: Matthias Braun <matthiasb at fb.com>
Date: 2021-10-28 (Thu, 28 Oct 2021)
Changed paths:
M llvm/lib/Target/X86/X86InstrInfo.cpp
M llvm/lib/Target/X86/X86InstrInfo.h
M llvm/test/CodeGen/X86/2007-02-16-BranchFold.ll
M llvm/test/CodeGen/X86/optimize-compare.mir
M llvm/test/CodeGen/X86/postalloc-coalescing.ll
Log Message:
-----------
X86InstrInfo: Optimize more combinations of SUB+CMP
`X86InstrInfo::optimizeCompareInstr` would only optimize a `SUB`
followed by a `CMP` in `isRedundantFlagInstr`. This extends the code to
also look for other combinations like `CMP`+`CMP`, `TEST`+`TEST`, `SUB
x,0`+`TEST`.
- Change `isRedundantFlagInstr` to run `analyzeCompareInstr` on the
candidate instruction and compare the results. This normalizes things
and gives consistent results for various comparisons (`CMP x, y`,
`SUB x, y`) and immediate cases (`TEST x, x`, `SUB x, 0`,
`CMP x, 0`...).
- Turn `isRedundantFlagInstr` into a member function so it can call
`analyzeCompare`. - We now also check `isRedundantFlagInstr` even if
`IsCmpZero` is true, since we now have cases like `TEST`+`TEST`.
Differential Revision: https://reviews.llvm.org/D110865
Commit: e2c7ee0743592e39274e28dbe0d0c213ba342317
https://github.com/llvm/llvm-project/commit/e2c7ee0743592e39274e28dbe0d0c213ba342317
Author: Matthias Braun <matthiasb at fb.com>
Date: 2021-10-28 (Thu, 28 Oct 2021)
Changed paths:
M llvm/lib/Target/X86/X86InstrInfo.cpp
M llvm/lib/Target/X86/X86InstrInfo.h
M llvm/test/CodeGen/X86/optimize-compare.mir
A llvm/test/CodeGen/X86/peep-test-5.ll
M llvm/test/CodeGen/X86/use-cr-result-of-dom-icmp-st.ll
Log Message:
-----------
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
Compare: https://github.com/llvm/llvm-project/compare/e50f02ba7ed8...e2c7ee074359
More information about the All-commits
mailing list