xref: /aosp_15_r20/external/llvm/test/CodeGen/Mips/longbranch.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=mipsel -relocation-model=pic < %s | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=mipsel -force-mips-long-branch -O3 -relocation-model=pic < %s \
3*9880d681SAndroid Build Coastguard Worker; RUN:   | FileCheck %s -check-prefix=O32
4*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=mipsel -mcpu=mips32r6 -force-mips-long-branch -O3 \
5*9880d681SAndroid Build Coastguard Worker; RUN:   -relocation-model=pic -asm-show-inst < %s | FileCheck %s -check-prefix=O32-R6
6*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=mips64el -mcpu=mips4 -target-abi=n64 -force-mips-long-branch -O3 -relocation-model=pic \
7*9880d681SAndroid Build Coastguard Worker; RUN:   < %s | FileCheck %s -check-prefix=N64
8*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=mips64el -mcpu=mips64 -target-abi=n64 -force-mips-long-branch -O3 -relocation-model=pic \
9*9880d681SAndroid Build Coastguard Worker; RUN:   < %s | FileCheck %s -check-prefix=N64
10*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=mips64el -mcpu=mips64r6 -target-abi=n64 -force-mips-long-branch -O3 \
11*9880d681SAndroid Build Coastguard Worker; RUN:   -relocation-model=pic -asm-show-inst < %s | FileCheck %s -check-prefix=N64-R6
12*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=mipsel -mcpu=mips32r2 -mattr=micromips \
13*9880d681SAndroid Build Coastguard Worker; RUN:   -force-mips-long-branch -O3 -relocation-model=pic < %s | FileCheck %s -check-prefix=MICROMIPS
14*9880d681SAndroid Build Coastguard Worker; RUN: llc -mtriple=mipsel-none-nacl -force-mips-long-branch -O3 -relocation-model=pic < %s \
15*9880d681SAndroid Build Coastguard Worker; RUN:   | FileCheck %s -check-prefix=NACL
16*9880d681SAndroid Build Coastguard Worker
17*9880d681SAndroid Build Coastguard Worker
18*9880d681SAndroid Build Coastguard Worker@x = external global i32
19*9880d681SAndroid Build Coastguard Worker
20*9880d681SAndroid Build Coastguard Workerdefine void @test1(i32 signext %s) {
21*9880d681SAndroid Build Coastguard Workerentry:
22*9880d681SAndroid Build Coastguard Worker  %cmp = icmp eq i32 %s, 0
23*9880d681SAndroid Build Coastguard Worker  br i1 %cmp, label %end, label %then
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard Workerthen:
26*9880d681SAndroid Build Coastguard Worker  store i32 1, i32* @x, align 4
27*9880d681SAndroid Build Coastguard Worker  br label %end
28*9880d681SAndroid Build Coastguard Worker
29*9880d681SAndroid Build Coastguard Workerend:
30*9880d681SAndroid Build Coastguard Worker  ret void
31*9880d681SAndroid Build Coastguard Worker
32*9880d681SAndroid Build Coastguard Worker
33*9880d681SAndroid Build Coastguard Worker; First check the normal version (without long branch).  beqz jumps to return,
34*9880d681SAndroid Build Coastguard Worker; and fallthrough block stores 1 to global variable.
35*9880d681SAndroid Build Coastguard Worker
36*9880d681SAndroid Build Coastguard Worker; CHECK:        lui     $[[R0:[0-9]+]], %hi(_gp_disp)
37*9880d681SAndroid Build Coastguard Worker; CHECK:        addiu   $[[R0]], $[[R0]], %lo(_gp_disp)
38*9880d681SAndroid Build Coastguard Worker; CHECK:        beqz    $4, $[[BB0:BB[0-9_]+]]
39*9880d681SAndroid Build Coastguard Worker; CHECK:        addu    $[[GP:[0-9]+]], $[[R0]], $25
40*9880d681SAndroid Build Coastguard Worker; CHECK:        lw      $[[R1:[0-9]+]], %got(x)($[[GP]])
41*9880d681SAndroid Build Coastguard Worker; CHECK:        addiu   $[[R2:[0-9]+]], $zero, 1
42*9880d681SAndroid Build Coastguard Worker; CHECK:        sw      $[[R2]], 0($[[R1]])
43*9880d681SAndroid Build Coastguard Worker; CHECK:   $[[BB0]]:
44*9880d681SAndroid Build Coastguard Worker; CHECK:        jr      $ra
45*9880d681SAndroid Build Coastguard Worker; CHECK:        nop
46*9880d681SAndroid Build Coastguard Worker
47*9880d681SAndroid Build Coastguard Worker
48*9880d681SAndroid Build Coastguard Worker; Check the MIPS32 version.  Check that branch logic is inverted, so that the
49*9880d681SAndroid Build Coastguard Worker; target of the new branch (bnez) is the fallthrough block of the original
50*9880d681SAndroid Build Coastguard Worker; branch.  Check that fallthrough block of the new branch contains long branch
51*9880d681SAndroid Build Coastguard Worker; expansion which at the end indirectly jumps to the target of the original
52*9880d681SAndroid Build Coastguard Worker; branch.
53*9880d681SAndroid Build Coastguard Worker
54*9880d681SAndroid Build Coastguard Worker; O32:        lui     $[[R0:[0-9]+]], %hi(_gp_disp)
55*9880d681SAndroid Build Coastguard Worker; O32:        addiu   $[[R0]], $[[R0]], %lo(_gp_disp)
56*9880d681SAndroid Build Coastguard Worker; O32:        bnez    $4, $[[BB0:BB[0-9_]+]]
57*9880d681SAndroid Build Coastguard Worker; O32:        addu    $[[GP:[0-9]+]], $[[R0]], $25
58*9880d681SAndroid Build Coastguard Worker
59*9880d681SAndroid Build Coastguard Worker; Check for long branch expansion:
60*9880d681SAndroid Build Coastguard Worker; O32:             addiu   $sp, $sp, -8
61*9880d681SAndroid Build Coastguard Worker; O32-NEXT:        sw      $ra, 0($sp)
62*9880d681SAndroid Build Coastguard Worker; O32-NEXT:        lui     $1, %hi(($[[BB2:BB[0-9_]+]])-($[[BB1:BB[0-9_]+]]))
63*9880d681SAndroid Build Coastguard Worker; O32-NEXT:        bal     $[[BB1]]
64*9880d681SAndroid Build Coastguard Worker; O32-NEXT:        addiu   $1, $1, %lo(($[[BB2]])-($[[BB1]]))
65*9880d681SAndroid Build Coastguard Worker; O32-NEXT:   $[[BB1]]:
66*9880d681SAndroid Build Coastguard Worker; O32-NEXT:        addu    $1, $ra, $1
67*9880d681SAndroid Build Coastguard Worker; O32-NEXT:        lw      $ra, 0($sp)
68*9880d681SAndroid Build Coastguard Worker; O32-NEXT:        jr      $1
69*9880d681SAndroid Build Coastguard Worker; O32-NEXT:        addiu   $sp, $sp, 8
70*9880d681SAndroid Build Coastguard Worker
71*9880d681SAndroid Build Coastguard Worker; O32:   $[[BB0]]:
72*9880d681SAndroid Build Coastguard Worker; O32:        lw      $[[R1:[0-9]+]], %got(x)($[[GP]])
73*9880d681SAndroid Build Coastguard Worker; O32:        addiu   $[[R2:[0-9]+]], $zero, 1
74*9880d681SAndroid Build Coastguard Worker; O32:        sw      $[[R2]], 0($[[R1]])
75*9880d681SAndroid Build Coastguard Worker; O32:   $[[BB2]]:
76*9880d681SAndroid Build Coastguard Worker; O32:        jr      $ra
77*9880d681SAndroid Build Coastguard Worker; O32:        nop
78*9880d681SAndroid Build Coastguard Worker
79*9880d681SAndroid Build Coastguard Worker; In MIPS32R6 JR is an alias to JALR with $rd=0. As everything else remains the
80*9880d681SAndroid Build Coastguard Worker; same with the O32 prefix, we use -asm-show-inst in order to make sure that
81*9880d681SAndroid Build Coastguard Worker; the opcode of the MachineInst is a JALR.
82*9880d681SAndroid Build Coastguard Worker; O32-R6:     JALR
83*9880d681SAndroid Build Coastguard Worker
84*9880d681SAndroid Build Coastguard Worker; Check the MIPS64 version.
85*9880d681SAndroid Build Coastguard Worker
86*9880d681SAndroid Build Coastguard Worker; N64:        lui     $[[R0:[0-9]+]], %hi(%neg(%gp_rel(test1)))
87*9880d681SAndroid Build Coastguard Worker; N64:        bnez    $4, $[[BB0:BB[0-9_]+]]
88*9880d681SAndroid Build Coastguard Worker; N64:        daddu   $[[R1:[0-9]+]], $[[R0]], $25
89*9880d681SAndroid Build Coastguard Worker
90*9880d681SAndroid Build Coastguard Worker; Check for long branch expansion:
91*9880d681SAndroid Build Coastguard Worker; N64:           daddiu  $sp, $sp, -16
92*9880d681SAndroid Build Coastguard Worker; N64-NEXT:      sd      $ra, 0($sp)
93*9880d681SAndroid Build Coastguard Worker; N64-NEXT:      daddiu  $1, $zero, %hi(($[[BB2:BB[0-9_]+]])-($[[BB1:BB[0-9_]+]]))
94*9880d681SAndroid Build Coastguard Worker; N64-NEXT:      dsll    $1, $1, 16
95*9880d681SAndroid Build Coastguard Worker; N64-NEXT:      bal     $[[BB1]]
96*9880d681SAndroid Build Coastguard Worker; N64-NEXT:      daddiu  $1, $1, %lo(($[[BB2]])-($[[BB1]]))
97*9880d681SAndroid Build Coastguard Worker; N64-NEXT:  $[[BB1]]:
98*9880d681SAndroid Build Coastguard Worker; N64-NEXT:      daddu   $1, $ra, $1
99*9880d681SAndroid Build Coastguard Worker; N64-NEXT:      ld      $ra, 0($sp)
100*9880d681SAndroid Build Coastguard Worker; N64-NEXT:      jr      $1
101*9880d681SAndroid Build Coastguard Worker; N64-NEXT:      daddiu  $sp, $sp, 16
102*9880d681SAndroid Build Coastguard Worker
103*9880d681SAndroid Build Coastguard Worker; N64:   $[[BB0]]:
104*9880d681SAndroid Build Coastguard Worker; N64:        daddiu  $[[GP:[0-9]+]], $[[R1]], %lo(%neg(%gp_rel(test1)))
105*9880d681SAndroid Build Coastguard Worker; N64:        ld      $[[R2:[0-9]+]], %got_disp(x)($[[GP]])
106*9880d681SAndroid Build Coastguard Worker; N64:        addiu   $[[R3:[0-9]+]], $zero, 1
107*9880d681SAndroid Build Coastguard Worker; N64:        sw      $[[R3]], 0($[[R2]])
108*9880d681SAndroid Build Coastguard Worker; N64:   $[[BB2]]:
109*9880d681SAndroid Build Coastguard Worker; N64:        jr      $ra
110*9880d681SAndroid Build Coastguard Worker; N64:        nop
111*9880d681SAndroid Build Coastguard Worker
112*9880d681SAndroid Build Coastguard Worker; In MIPS64R6 JR is an alias to JALR with $rd=0. As everything else remains the
113*9880d681SAndroid Build Coastguard Worker; same with the N64 prefix, we use -asm-show-inst in order to make sure that
114*9880d681SAndroid Build Coastguard Worker; the opcode of the MachineInst is a JALR.
115*9880d681SAndroid Build Coastguard Worker; N64-R6:     JALR64
116*9880d681SAndroid Build Coastguard Worker
117*9880d681SAndroid Build Coastguard Worker
118*9880d681SAndroid Build Coastguard Worker; Check the microMIPS version.
119*9880d681SAndroid Build Coastguard Worker
120*9880d681SAndroid Build Coastguard Worker; MICROMIPS:        lui     $[[R0:[0-9]+]], %hi(_gp_disp)
121*9880d681SAndroid Build Coastguard Worker; MICROMIPS:        addiu   $[[R0]], $[[R0]], %lo(_gp_disp)
122*9880d681SAndroid Build Coastguard Worker; MICROMIPS:        bnez    $4, $[[BB0:BB[0-9_]+]]
123*9880d681SAndroid Build Coastguard Worker; MICROMIPS:        addu    $[[GP:[0-9]+]], $[[R0]], $25
124*9880d681SAndroid Build Coastguard Worker
125*9880d681SAndroid Build Coastguard Worker; Check for long branch expansion:
126*9880d681SAndroid Build Coastguard Worker; MICROMIPS:          addiu   $sp, $sp, -8
127*9880d681SAndroid Build Coastguard Worker; MICROMIPS-NEXT:     sw      $ra, 0($sp)
128*9880d681SAndroid Build Coastguard Worker; MICROMIPS-NEXT:     lui     $1, %hi(($[[BB2:BB[0-9_]+]])-($[[BB1:BB[0-9_]+]]))
129*9880d681SAndroid Build Coastguard Worker; MICROMIPS-NEXT:     bal     $[[BB1]]
130*9880d681SAndroid Build Coastguard Worker; MICROMIPS-NEXT:     addiu   $1, $1, %lo(($[[BB2]])-($[[BB1]]))
131*9880d681SAndroid Build Coastguard Worker; MICROMIPS-NEXT:  $[[BB1]]:
132*9880d681SAndroid Build Coastguard Worker; MICROMIPS-NEXT:     addu    $1, $ra, $1
133*9880d681SAndroid Build Coastguard Worker; MICROMIPS-NEXT:     lw      $ra, 0($sp)
134*9880d681SAndroid Build Coastguard Worker; MICROMIPS-NEXT:     jr      $1
135*9880d681SAndroid Build Coastguard Worker; MICROMIPS-NEXT:     addiu   $sp, $sp, 8
136*9880d681SAndroid Build Coastguard Worker
137*9880d681SAndroid Build Coastguard Worker; MICROMIPS:   $[[BB0]]:
138*9880d681SAndroid Build Coastguard Worker; MICROMIPS:        lw      $[[R1:[0-9]+]], %got(x)($[[GP]])
139*9880d681SAndroid Build Coastguard Worker; MICROMIPS:        li16    $[[R2:[0-9]+]], 1
140*9880d681SAndroid Build Coastguard Worker; MICROMIPS:        sw16    $[[R2]], 0($[[R1]])
141*9880d681SAndroid Build Coastguard Worker; MICROMIPS:   $[[BB2]]:
142*9880d681SAndroid Build Coastguard Worker; MICROMIPS:        jrc      $ra
143*9880d681SAndroid Build Coastguard Worker
144*9880d681SAndroid Build Coastguard Worker
145*9880d681SAndroid Build Coastguard Worker; Check the NaCl version.  Check that sp change is not in the branch delay slot
146*9880d681SAndroid Build Coastguard Worker; of "jr $1" instruction.  Check that target of indirect branch "jr $1" is
147*9880d681SAndroid Build Coastguard Worker; bundle aligned.
148*9880d681SAndroid Build Coastguard Worker
149*9880d681SAndroid Build Coastguard Worker; NACL:        lui     $[[R0:[0-9]+]], %hi(_gp_disp)
150*9880d681SAndroid Build Coastguard Worker; NACL:        addiu   $[[R0]], $[[R0]], %lo(_gp_disp)
151*9880d681SAndroid Build Coastguard Worker; NACL:        bnez    $4, $[[BB0:BB[0-9_]+]]
152*9880d681SAndroid Build Coastguard Worker; NACL:        addu    $[[GP:[0-9]+]], $[[R0]], $25
153*9880d681SAndroid Build Coastguard Worker
154*9880d681SAndroid Build Coastguard Worker; Check for long branch expansion:
155*9880d681SAndroid Build Coastguard Worker; NACL:             addiu   $sp, $sp, -8
156*9880d681SAndroid Build Coastguard Worker; NACL-NEXT:        sw      $ra, 0($sp)
157*9880d681SAndroid Build Coastguard Worker; NACL-NEXT:        lui     $1, %hi(($[[BB2:BB[0-9_]+]])-($[[BB1:BB[0-9_]+]]))
158*9880d681SAndroid Build Coastguard Worker; NACL-NEXT:        bal     $[[BB1]]
159*9880d681SAndroid Build Coastguard Worker; NACL-NEXT:        addiu   $1, $1, %lo(($[[BB2]])-($[[BB1]]))
160*9880d681SAndroid Build Coastguard Worker; NACL-NEXT:   $[[BB1]]:
161*9880d681SAndroid Build Coastguard Worker; NACL-NEXT:        addu    $1, $ra, $1
162*9880d681SAndroid Build Coastguard Worker; NACL-NEXT:        lw      $ra, 0($sp)
163*9880d681SAndroid Build Coastguard Worker; NACL-NEXT:        addiu   $sp, $sp, 8
164*9880d681SAndroid Build Coastguard Worker; NACL-NEXT:        jr      $1
165*9880d681SAndroid Build Coastguard Worker; NACL-NEXT:        nop
166*9880d681SAndroid Build Coastguard Worker
167*9880d681SAndroid Build Coastguard Worker; NACL:        $[[BB0]]:
168*9880d681SAndroid Build Coastguard Worker; NACL:             lw      $[[R1:[0-9]+]], %got(x)($[[GP]])
169*9880d681SAndroid Build Coastguard Worker; NACL:             addiu   $[[R2:[0-9]+]], $zero, 1
170*9880d681SAndroid Build Coastguard Worker; NACL:             sw      $[[R2]], 0($[[R1]])
171*9880d681SAndroid Build Coastguard Worker; NACL:             .p2align  4
172*9880d681SAndroid Build Coastguard Worker; NACL-NEXT:   $[[BB2]]:
173*9880d681SAndroid Build Coastguard Worker; NACL:             jr      $ra
174*9880d681SAndroid Build Coastguard Worker; NACL:             nop
175*9880d681SAndroid Build Coastguard Worker}
176