Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 925f591

Browse files
committed
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356809 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 93b589a commit 925f591

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

lib/Target/ARM/ARMBaseInstrInfo.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -2869,7 +2869,15 @@ bool ARMBaseInstrInfo::optimizeCompareInstr(
28692869
// change. We can't do this transformation.
28702870
return false;
28712871

2872-
} while (I != B);
2872+
if (I == B) {
2873+
// In some cases, we scan the use-list of an instruction for an AND;
2874+
// that AND is in the same BB, but may not be scheduled before the
2875+
// corresponding TST. In that case, bail out.
2876+
//
2877+
// FIXME: We could try to reschedule the AND.
2878+
return false;
2879+
}
2880+
} while (true);
28732881

28742882
// Return false if no candidates exist.
28752883
if (!MI && !SubAdd)

test/CodeGen/ARM/tst-peephole.mir

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# RUN: llc -run-pass=peephole-opt %s -o - -verify-machineinstrs | FileCheck %s
2+
3+
# The and -> ands transform is sensitive to scheduling; make sure we don't
4+
# transform cases which aren't legal.
5+
6+
# CHECK-LABEL: name: foo_transform
7+
# CHECK: %2:gpr = ANDri %0, 1, 14, $noreg, def $cpsr
8+
# CHECK-NEXT: %3:gpr = MOVCCi16 %1, 5, 0, $cpsr
9+
10+
# CHECK-LABEL: name: foo_notransform
11+
# CHECK: TSTri %0, 1, 14, $noreg, implicit-def $cpsr
12+
# CHECK-NEXT: %2:gpr = MOVCCi16 %1, 5, 0, $cpsr
13+
14+
--- |
15+
target triple = "armv7-unknown-unknown"
16+
define i32 @foo_transform(i32 %in) {
17+
ret i32 undef
18+
}
19+
define i32 @foo_notransform(i32 %in) {
20+
ret i32 undef
21+
}
22+
23+
...
24+
---
25+
name: foo_transform
26+
tracksRegLiveness: true
27+
body: |
28+
bb.0 (%ir-block.0):
29+
liveins: $r0
30+
31+
%1:gpr = COPY $r0
32+
%2:gpr = MOVi 4, 14, $noreg, $noreg
33+
%4:gpr = ANDri %1:gpr, 1, 14, $noreg, $noreg
34+
TSTri %1:gpr, 1, 14, $noreg, implicit-def $cpsr
35+
%3:gpr = MOVCCi16 %2, 5, 0, $cpsr
36+
$r0 = COPY killed %3
37+
$r1 = COPY killed %4
38+
BX_RET 14, $noreg, implicit $r0, implicit $r1
39+
...
40+
name: foo_notransform
41+
tracksRegLiveness: true
42+
body: |
43+
bb.0 (%ir-block.0):
44+
liveins: $r0
45+
46+
%1:gpr = COPY $r0
47+
%2:gpr = MOVi 4, 14, $noreg, $noreg
48+
TSTri %1:gpr, 1, 14, $noreg, implicit-def $cpsr
49+
%3:gpr = MOVCCi16 %2, 5, 0, $cpsr
50+
%4:gpr = ANDri %1:gpr, 1, 14, $noreg, $noreg
51+
$r0 = COPY killed %3
52+
$r1 = COPY killed %4
53+
BX_RET 14, $noreg, implicit $r0, implicit $r1
54+

0 commit comments

Comments
 (0)