[PATCH] D124118: [Peephole-Opt] For one kind of test-after-add pattern, eliminates test if it's correct to do so.

Mingming Liu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 20 12:38:34 PDT 2022


mingmingl created this revision.
mingmingl added reviewers: Carrot, davidxl.
Herald added subscribers: pengfei, hiraditya.
Herald added a project: All.
mingmingl requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The goal of this patch is to optimize away the test instruction in the following pattern

%reg = and ...      // EFLAGS set
 ...                         // EFLAGS not changed.
%extended_reg = subreg_to_reg 0, %reg, %subreg.sub_index. // EFLAGS not changed
testrr %extended_reg, %extended_reg, implicit-def $eflags.  // This could be optimized away.

Before this patch, the optimization wasn't carried out, since `extended_reg` is defined by SUBREG_TO_REG, which is not handled by `isDefConvertible` in `X86InstrInfo.cpp`.

The implementation add a heuristic to optimize away the `test` if EFLAGS doesn't change since it's set last time.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124118

Files:
  llvm/lib/Target/X86/X86InstrInfo.cpp
  llvm/test/CodeGen/X86/peephole-test-after-add.mir
  llvm/test/CodeGen/X86/pr-placeholder.mir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124118.423997.patch
Type: text/x-patch
Size: 16668 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220420/a1bb94fa/attachment.bin>


More information about the llvm-commits mailing list