Skip to content

Commit f56ddde

Browse files
authored
[ARM] Restore hasSideEffects flag on t2WhileLoopSetup (#168948)
ARM relies on deprecated TableGen behavior of guessing instruction properties from patterns (`def ARM : Target` doesn't have `guessInstructionProperties` set to false). Before #168209, TableGen conservatively guessed that `t2WhileLoopSetup` has side effects because the instruction wasn't matched by any pattern. After the patch, TableGen guesses it has no side effects because the added pattern uses only `arm_wlssetup` node, which has no side effects. Add `SDNPSideEffect` to the node so that TableGen guesses the property right, and also `hasSideEffects = 1` to the instruction in case ARM ever sets `guessInstructionProperties` to false.
1 parent 76a6816 commit f56ddde

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

llvm/lib/Target/ARM/ARMInstrThumb2.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5584,7 +5584,8 @@ class t2LOL<dag oops, dag iops, string asm, string ops>
55845584
// Setup for the iteration count of a WLS. See t2WhileLoopSetup.
55855585
def arm_wlssetup
55865586
: SDNode<"ARMISD::WLSSETUP",
5587-
SDTypeProfile<1, 1, [SDTCisInt<0>, SDTCisSameAs<1, 0>]>>;
5587+
SDTypeProfile<1, 1, [SDTCisInt<0>, SDTCisSameAs<1, 0>]>,
5588+
[SDNPSideEffect]>;
55885589

55895590
// Low-overhead loops, While Loop Start branch. See t2WhileLoopStart
55905591
def arm_wls : SDNode<"ARMISD::WLS",
@@ -5668,6 +5669,7 @@ def t2DoLoopStartTP :
56685669
// t2WhileLoopSetup to setup LR and t2WhileLoopStart to perform the branch. Not
56695670
// valid after reg alloc, as it should be lowered during MVETPAndVPTOptimisations
56705671
// into a t2WhileLoopStartLR (or expanded).
5672+
let hasSideEffects = 1 in
56715673
def t2WhileLoopSetup :
56725674
t2PseudoInst<(outs GPRlr:$lr), (ins rGPR:$tc), 4, IIC_Br,
56735675
[(set i32:$lr, (arm_wlssetup i32:$tc))]>;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
2+
; RUN: llc -mtriple=thumbv8.1m.main %s -o - | FileCheck %s
3+
4+
; Checks that t2WhileLoopSetup is not CSEd.
5+
6+
define i32 @test(i16 %arg) {
7+
; CHECK-LABEL: test:
8+
; CHECK: @ %bb.0: @ %bb
9+
; CHECK-NEXT: push {r7, lr}
10+
; CHECK-NEXT: uxth r0, r0
11+
; CHECK-NEXT: wls lr, r0, .LBB0_4
12+
; CHECK-NEXT: .LBB0_1: @ %bb3
13+
; CHECK-NEXT: @ =>This Inner Loop Header: Depth=1
14+
; CHECK-NEXT: le lr, .LBB0_1
15+
; CHECK-NEXT: @ %bb.2: @ %bb2
16+
; CHECK-NEXT: wls lr, r0, .LBB0_4
17+
; CHECK-NEXT: .LBB0_3: @ %bb7
18+
; CHECK-NEXT: @ =>This Inner Loop Header: Depth=1
19+
; CHECK-NEXT: le lr, .LBB0_3
20+
; CHECK-NEXT: .LBB0_4: @ %.critedge
21+
; CHECK-NEXT: movs r0, #0
22+
; CHECK-NEXT: pop {r7, pc}
23+
bb:
24+
%i = zext i16 %arg to i32
25+
%i1 = icmp eq i16 %arg, 0
26+
br i1 %i1, label %.critedge, label %bb3
27+
28+
bb2: ; preds = %bb3
29+
br i1 %i1, label %.critedge, label %bb7
30+
31+
bb3: ; preds = %bb3, %bb
32+
%i4 = phi i32 [ %i5, %bb3 ], [ 0, %bb ]
33+
%i5 = add i32 %i4, 1
34+
%i6 = icmp eq i32 %i5, %i
35+
br i1 %i6, label %bb2, label %bb3
36+
37+
bb7: ; preds = %bb7, %bb2
38+
%i8 = phi i32 [ %i9, %bb7 ], [ 0, %bb2 ]
39+
%i9 = add i32 %i8, 1
40+
%i10 = icmp eq i32 %i9, %i
41+
br i1 %i10, label %.critedge, label %bb7
42+
43+
.critedge: ; preds = %bb7, %bb2, %bb
44+
ret i32 0
45+
}

0 commit comments

Comments
 (0)