[PATCH] D110865: X86InstrInfo: Optimize more combinations of SUB+CMP

Matthias Braun via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 30 11:10:04 PDT 2021


MatzeB created this revision.
MatzeB added reviewers: RKSimon, craig.topper, nikic, manmanren.
Herald added subscribers: wenlei, pengfei, hiraditya, mcrosier.
MatzeB requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Previously `optimizeCompareInstr` would only optimize a `SUB` followed by a `CMP` in the `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`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110865

Files:
  llvm/lib/Target/X86/X86InstrInfo.cpp
  llvm/lib/Target/X86/X86InstrInfo.h
  llvm/test/CodeGen/X86/2007-02-16-BranchFold.ll
  llvm/test/CodeGen/X86/optimize-compare.mir
  llvm/test/CodeGen/X86/postalloc-coalescing.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110865.376291.patch
Type: text/x-patch
Size: 15567 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210930/7a36d9f5/attachment.bin>


More information about the llvm-commits mailing list