llvm.org GIT mirror llvm / 196c8e5
ARM: correctly determine final tBX_LR in Thumb1 functions The changes caused by folding an sp-adjustment into a "pop" previously disrupted the forward search for the final real instruction in a terminating block. This switches to a backward search (skipping debug instrs). This fixes PR18399. Patch by Zhaoshi. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199266 91177308-0d34-0410-b5e6-96231b3b80d8 Tim Northover 6 years ago
2 changed file(s) with 26 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
303303 // we need to update the SP after popping the value. Therefore, we
304304 // pop the old LR into R3 as a temporary.
305305
306 // Move back past the callee-saved register restoration
307 while (MBBI != MBB.end() && isCSRestore(MBBI, CSRegs))
308 ++MBBI;
306 // Get the last instruction, tBX_RET
307 MBBI = MBB.getLastNonDebugInstr();
308 assert (MBBI->getOpcode() == ARM::tBX_RET);
309309 // Epilogue for vararg functions: pop LR to R3 and branch off it.
310310 AddDefaultPred(BuildMI(MBB, MBBI, dl, TII.get(ARM::tPOP)))
311311 .addReg(ARM::R3, RegState::Define);
161161 ; the correct edge-case (first inst in block is correct one to adjust).
162162 ret void
163163 }
164
165 define void @test_varsize(...) minsize {
166 ; CHECK-T1-LABEL: test_varsize:
167 ; CHECK-T1: sub sp, #16
168 ; CHECK-T1: push {r2, r3, r4, r5, r7, lr}
169 ; ...
170 ; CHECK-T1: pop {r2, r3, r4, r5, r7}
171 ; CHECK-T1: pop {r3}
172 ; CHECK-T1: add sp, #16
173 ; CHECK-T1: bx r3
174
175 ; CHECK-LABEL: test_varsize:
176 ; CHECK: sub sp, #16
177 ; CHECK: push {r5, r6, r7, lr}
178 ; ...
179 ; CHECK: pop.w {r2, r3, r7, lr}
180 ; CHECK: add sp, #16
181 ; CHECK: bx lr
182
183 %var = alloca i8, i32 8
184 call void @bar(i8* %var)
185 ret void
186 }