[llvm] r356809 - [ARM] Don't form "ands" when it isn't scheduled correctly.

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 22 13:49:16 PDT 2019


Author: efriedma
Date: Fri Mar 22 13:49:15 2019
New Revision: 356809

URL: http://llvm.org/viewvc/llvm-project?rev=356809&view=rev
Log:
[ARM] Don't form "ands" when it isn't scheduled correctly.

In r322972/r323136, the iteration here was changed to catch cases at the
beginning of a basic block... but we accidentally deleted an important
safety check.  Restore that check to the way it was.

Fixes https://bugs.llvm.org/show_bug.cgi?id=41116

Differential Revision: https://reviews.llvm.org/D59680


Added:
    llvm/trunk/test/CodeGen/ARM/tst-peephole.mir
Modified:
    llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp

Modified: llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp?rev=356809&r1=356808&r2=356809&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp Fri Mar 22 13:49:15 2019
@@ -2869,7 +2869,15 @@ bool ARMBaseInstrInfo::optimizeCompareIn
       // change. We can't do this transformation.
       return false;
 
-  } while (I != B);
+    if (I == B) {
+      // In some cases, we scan the use-list of an instruction for an AND;
+      // that AND is in the same BB, but may not be scheduled before the
+      // corresponding TST.  In that case, bail out.
+      //
+      // FIXME: We could try to reschedule the AND.
+      return false;
+    }
+  } while (true);
 
   // Return false if no candidates exist.
   if (!MI && !SubAdd)

Added: llvm/trunk/test/CodeGen/ARM/tst-peephole.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/tst-peephole.mir?rev=356809&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/tst-peephole.mir (added)
+++ llvm/trunk/test/CodeGen/ARM/tst-peephole.mir Fri Mar 22 13:49:15 2019
@@ -0,0 +1,54 @@
+# RUN: llc -run-pass=peephole-opt %s -o - -verify-machineinstrs | FileCheck %s
+
+# The and -> ands transform is sensitive to scheduling; make sure we don't
+# transform cases which aren't legal.
+
+# CHECK-LABEL: name: foo_transform
+# CHECK:      %2:gpr = ANDri %0, 1, 14, $noreg, def $cpsr
+# CHECK-NEXT: %3:gpr = MOVCCi16 %1, 5, 0, $cpsr
+
+# CHECK-LABEL: name: foo_notransform
+# CHECK:      TSTri %0, 1, 14, $noreg, implicit-def $cpsr
+# CHECK-NEXT: %2:gpr = MOVCCi16 %1, 5, 0, $cpsr
+
+--- |
+  target triple = "armv7-unknown-unknown"
+  define i32 @foo_transform(i32 %in) {
+    ret i32 undef
+  }
+  define i32 @foo_notransform(i32 %in) {
+    ret i32 undef
+  }
+
+...
+---
+name:            foo_transform
+tracksRegLiveness: true
+body:             |
+  bb.0 (%ir-block.0):
+    liveins: $r0
+
+    %1:gpr = COPY $r0
+    %2:gpr = MOVi 4, 14, $noreg, $noreg
+    %4:gpr = ANDri %1:gpr, 1, 14, $noreg, $noreg
+    TSTri %1:gpr, 1, 14, $noreg, implicit-def $cpsr
+    %3:gpr = MOVCCi16 %2, 5, 0, $cpsr
+    $r0 = COPY killed %3
+    $r1 = COPY killed %4
+    BX_RET 14, $noreg, implicit $r0, implicit $r1
+...
+name:            foo_notransform
+tracksRegLiveness: true
+body:             |
+  bb.0 (%ir-block.0):
+    liveins: $r0
+
+    %1:gpr = COPY $r0
+    %2:gpr = MOVi 4, 14, $noreg, $noreg
+    TSTri %1:gpr, 1, 14, $noreg, implicit-def $cpsr
+    %3:gpr = MOVCCi16 %2, 5, 0, $cpsr
+    %4:gpr = ANDri %1:gpr, 1, 14, $noreg, $noreg
+    $r0 = COPY killed %3
+    $r1 = COPY killed %4
+    BX_RET 14, $noreg, implicit $r0, implicit $r1
+




More information about the llvm-commits mailing list