This is an archive of the discontinued LLVM Phabricator instance.

X86InstrInfo: Refactor and cleanup optimizeCompareInstr
ClosedPublic

Authored by MatzeB on Sep 30 2021, 10:41 AM.

Details

Summary

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
...

Diff Detail

Event Timeline

MatzeB created this revision.Sep 30 2021, 10:41 AM
MatzeB requested review of this revision.Sep 30 2021, 10:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 30 2021, 10:41 AM
MatzeB edited the summary of this revision. (Show Details)Sep 30 2021, 10:42 AM
craig.topper accepted this revision.Sep 30 2021, 8:38 PM

Something about the logic for that forward scan loop for isUseDefConvertible has always bugged me. This is a nice improvement. LGTM

This revision is now accepted and ready to land.Sep 30 2021, 8:38 PM
foad added a subscriber: foad.Oct 1 2021, 6:21 AM
MatzeB updated this revision to Diff 376575.Oct 1 2021, 10:57 AM

comment tweaks.

MatzeB updated this revision to Diff 379758.Oct 14 2021, 10:16 AM
MatzeB retitled this revision from X86InstrInfo: Refactor and cleanup optimizeCompareInstr; NFC to X86InstrInfo: Refactor and cleanup optimizeCompareInstr.
MatzeB edited the summary of this revision. (Show Details)

Merged with D110863 as suggested.

RKSimon accepted this revision.Oct 14 2021, 10:55 AM

LGTM - cheers

This revision was automatically updated to reflect the committed changes.