llvm.org GIT mirror llvm / 86d9738
[PowerPC] Remove SeenUse check when optimizing conditional branch in PPCPreEmitPeephole pass. PPCPreEmitPeephole will convert a BC to B when the conditional branch is based on a constant CR by CRSET or CRUNSET. This is added in https://reviews.llvm.org/rL343100. When the conditional branch is known to be always taken, all branches will be removed and a new unconditional branch will be inserted. However, when SeenUse is false the original patch will not remove the branches, but still insert the new unconditional branch, update the successors and create inconsistent IR. Compiling the synthetic testcase included can show the problem we run into. The patch simply removes the SeenUse condition when adding branches into InstrsToErase set. Differential Revision: https://reviews.llvm.org/D56041 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350223 91177308-0d34-0410-b5e6-96231b3b80d8 Wei Mi 9 months ago
2 changed file(s) with 109 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
139139 // This conditional branch is always taken. So, remove all branches
140140 // and insert an unconditional branch to the destination of this.
141141 MachineBasicBlock::iterator It = Br, Er = MBB.end();
142 for (; It != Er && !SeenUse; It++) {
142 for (; It != Er; It++) {
143143 if (It->isDebugInstr()) continue;
144144 assert(It->isTerminator() && "Non-terminator after a terminator");
145145 InstrsToErase.push_back(&*It);
0 # RUN: llc -verify-machineinstrs -start-before=ppc-pre-emit-peephole %s -o - | FileCheck %s
1 --- |
2 target datalayout = "e-m:e-i64:64-n32:64"
3 target triple = "powerpc64le-unknown-linux-gnu"
4
5 declare signext i32 @callee(i32 signext)
6
7 define signext i32 @func(i32 signext %v) {
8 ret i32 0
9 }
10 ...
11 ---
12 name: func
13 alignment: 4
14 exposesReturnsTwice: false
15 legalized: false
16 regBankSelected: false
17 selected: false
18 failedISel: false
19 tracksRegLiveness: true
20 registers:
21 liveins:
22 - { reg: '$x3', virtual-reg: '' }
23 frameInfo:
24 isFrameAddressTaken: false
25 isReturnAddressTaken: false
26 hasStackMap: false
27 hasPatchPoint: false
28 stackSize: 48
29 offsetAdjustment: 0
30 maxAlignment: 0
31 adjustsStack: true
32 hasCalls: true
33 stackProtector: ''
34 maxCallFrameSize: 32
35 hasOpaqueSPAdjustment: false
36 hasVAStart: false
37 hasMustTailInVarArgFunc: false
38 localFrameSize: 0
39 savePoint: ''
40 restorePoint: ''
41 fixedStack:
42 - { id: 0, type: spill-slot, offset: -16, size: 8, alignment: 16, stack-id: 0,
43 callee-saved-register: '$x30', callee-saved-restored: true, debug-info-variable: '',
44 debug-info-expression: '', debug-info-location: '' }
45 stack:
46 constants:
47
48 body: |
49 bb.0:
50 successors: %bb.2(0x30000000), %bb.1(0x50000000)
51 liveins: $x3, $x30
52
53 ; bc should be converted into b
54 ; CHECK-LABEL: func
55 ; CHECK: # %bb.1
56 ; CHECK: creqv
57 ; CHECK-NOT: bc
58 ; CHECK: b .LBB0_3
59 ; CHECK: .LBB0_2
60
61 $x0 = MFLR8 implicit $lr8
62 STD killed $x0, 16, $x1
63 $x1 = STDU $x1, -48, $x1
64 STD killed $x30, 32, $x1 :: (store 8 into %fixed-stack.0, align 16)
65 $x30 = OR8 $x3, $x3
66 BL8_NOP @callee, csr_svr464_altivec, implicit-def dead $lr8, implicit $rm, implicit killed $x3, implicit $x2, implicit-def $r1, implicit-def $x3
67 renamable $cr0 = CMPLWI renamable $r3, 0
68 BCC 76, killed renamable $cr0, %bb.2
69
70 bb.1:
71 successors: %bb.5(0x40000000), %bb.2(0x40000000)
72 liveins: $x3
73
74 renamable $x3 = EXTSW_32_64 killed renamable $r3, implicit $x3
75 BL8_NOP @callee, csr_svr464_altivec, implicit-def dead $lr8, implicit $rm, implicit killed $x3, implicit $x2, implicit-def $r1, implicit-def $x3
76 renamable $cr2un = CRSET
77 $cr2gt = CROR $cr2un, $cr2un
78 $x30 = OR8 killed $x3, $x3
79 BC killed renamable $cr2un, %bb.5
80 B %bb.2
81
82 bb.4:
83 successors: %bb.5(0x80000000)
84 liveins: $x30
85
86 $x3 = LI8 0
87 BL8_NOP @callee, csr_svr464_altivec, implicit-def dead $lr8, implicit $rm, implicit killed $x3, implicit $x2, implicit-def $r1, implicit-def dead $x3
88
89 bb.5:
90 liveins: $x30, $cr0gt
91
92 renamable $x3 = EXTSW_32_64 killed renamable $r30, implicit $x30
93 $x30 = LD 32, $x1 :: (load 8 from %fixed-stack.0, align 16)
94 $x1 = ADDI8 $x1, 48
95 $x0 = LD 16, $x1
96 MTLR8 killed $x0, implicit-def $lr8
97 BLR8 implicit $lr8, implicit $rm, implicit killed $x3
98
99 bb.2:
100 successors: %bb.5(0x40000000), %bb.4(0x40000000)
101 liveins: $x30
102
103 renamable $cr0 = CMPWI renamable $r30, -1
104 BCn killed renamable $cr0gt, %bb.4
105 B %bb.5
106
107 ...