[PATCH] D110863: X86InstrInfo: Continue if there's other EFLAG readers between producers

Matthias Braun via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 30 11:02:22 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.

`optimizeCompareInstr` would stop searching if there are other EFLAG readers between the `CmpInstr` that we attempt to remove and the earlier instruction that we try to use instead. Example:

  = SUB32rr %0, %1, implicit-def $eflags
  ...  we no longer stop when there are $eflag users here
  CMP32rr %0, %1   ; will be removed
  ...

I don't see any reason why we cannot allow EFLAG readers between the two flag producers. Maybe it was an accident/artifact that wasn't obvious before the cleanups in D110857 <https://reviews.llvm.org/D110857>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110863

Files:
  llvm/lib/Target/X86/X86InstrInfo.cpp
  llvm/test/CodeGen/X86/optimize-compare.mir


Index: llvm/test/CodeGen/X86/optimize-compare.mir
===================================================================
--- llvm/test/CodeGen/X86/optimize-compare.mir
+++ llvm/test/CodeGen/X86/optimize-compare.mir
@@ -151,3 +151,23 @@
     CMP32rr %1, %0, implicit-def $eflags
     $bl = SETCCr 3, implicit $eflags
 ...
+---
+name: opt_redundant_flags_2
+body: |
+  bb.0:
+    ; CHECK-LABEL: name: opt_redundant_flags_2
+    ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
+    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr32 = COPY $edi
+    ; CHECK-NEXT: [[SUB32rr:%[0-9]+]]:gr32 = SUB32rr [[COPY]], [[COPY1]], implicit-def $eflags
+    ; CHECK-NEXT: $cl = SETCCr 2, implicit $eflags
+    ; CHECK-NEXT: $eax = COPY [[SUB32rr]]
+    ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
+    %0:gr32 = COPY $esi
+    %1:gr32 = COPY $edi
+    %2:gr32 = SUB32rr %0, %1, implicit-def $eflags
+    ; an extra eflags reader shouldn't stop optimization.
+    $cl = SETCCr 2, implicit $eflags
+    $eax = COPY %2
+    CMP32rr %0, %1, implicit-def $eflags
+    $bl = SETCCr 2, implicit $eflags
+...
Index: llvm/lib/Target/X86/X86InstrInfo.cpp
===================================================================
--- llvm/lib/Target/X86/X86InstrInfo.cpp
+++ llvm/lib/Target/X86/X86InstrInfo.cpp
@@ -4350,9 +4350,6 @@
         // Cannot do anything for any other EFLAG changes.
         return false;
       }
-
-      if (Inst.readsRegister(X86::EFLAGS, TRI))
-        return false;
     }
 
     if (MI || Sub)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110863.376289.patch
Type: text/x-patch
Size: 1478 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210930/ddc94843/attachment.bin>


More information about the llvm-commits mailing list