@@ -53,6 +53,7 @@ X86FrameLowering::X86FrameLowering(const X86Subtarget &STI,
53
53
STI(STI), TII(*STI.getInstrInfo()), TRI(STI.getRegisterInfo()) {
54
54
// Cache a bunch of frame-related predicates for this subtarget.
55
55
SlotSize = TRI->getSlotSize ();
56
+ assert (SlotSize == 4 || SlotSize == 8 );
56
57
Is64Bit = STI.is64Bit ();
57
58
IsLP64 = STI.isTarget64BitLP64 ();
58
59
// standard x86_64 uses 64-bit frame/stack pointers, x32 - 32-bit.
@@ -224,7 +225,7 @@ flagsNeedToBePreservedBeforeTheTerminators(const MachineBasicBlock &MBB) {
224
225
return false ;
225
226
}
226
227
227
- constexpr int64_t MaxSPChunk = (1LL << 31 ) - 1 ;
228
+ constexpr uint64_t MaxSPChunk = (1ULL << 31 ) - 1 ;
228
229
229
230
// / emitSPUpdate - Emit a series of instructions to increment / decrement the
230
231
// / stack pointer by a constant value.
@@ -245,8 +246,6 @@ void X86FrameLowering::emitSPUpdate(MachineBasicBlock &MBB,
245
246
return ;
246
247
}
247
248
248
- uint64_t Chunk = MaxSPChunk;
249
-
250
249
MachineFunction &MF = *MBB.getParent ();
251
250
const X86Subtarget &STI = MF.getSubtarget <X86Subtarget>();
252
251
const X86TargetLowering &TLI = *STI.getTargetLowering ();
@@ -260,7 +259,7 @@ void X86FrameLowering::emitSPUpdate(MachineBasicBlock &MBB,
260
259
// loop, by inlineStackProbe().
261
260
BuildMI (MBB, MBBI, DL, TII.get (X86::STACKALLOC_W_PROBING)).addImm (Offset);
262
261
return ;
263
- } else if (Offset > Chunk ) {
262
+ } else if (Offset > MaxSPChunk ) {
264
263
// Rather than emit a long series of instructions for large offsets,
265
264
// load the offset into a register and do one sub/add
266
265
unsigned Reg = 0 ;
@@ -284,7 +283,7 @@ void X86FrameLowering::emitSPUpdate(MachineBasicBlock &MBB,
284
283
.addReg (Reg);
285
284
MI->getOperand (3 ).setIsDead (); // The EFLAGS implicit def is dead.
286
285
return ;
287
- } else if (Offset > 8 * Chunk ) {
286
+ } else if (Offset > 8 * MaxSPChunk ) {
288
287
// If we would need more than 8 add or sub instructions (a >16GB stack
289
288
// frame), it's worth spilling RAX to materialize this immediate.
290
289
// pushq %rax
@@ -322,8 +321,7 @@ void X86FrameLowering::emitSPUpdate(MachineBasicBlock &MBB,
322
321
}
323
322
324
323
while (Offset) {
325
- uint64_t ThisVal = std::min (Offset, Chunk);
326
- if (ThisVal == SlotSize) {
324
+ if (Offset == SlotSize) {
327
325
// Use push / pop for slot sized adjustments as a size optimization. We
328
326
// need to find a dead register when using pop.
329
327
unsigned Reg = isSub ? (unsigned )(Is64Bit ? X86::RAX : X86::EAX)
@@ -334,11 +332,12 @@ void X86FrameLowering::emitSPUpdate(MachineBasicBlock &MBB,
334
332
BuildMI (MBB, MBBI, DL, TII.get (Opc))
335
333
.addReg (Reg, getDefRegState (!isSub) | getUndefRegState (isSub))
336
334
.setMIFlag (Flag);
337
- Offset -= ThisVal;
338
- continue ;
335
+ return ;
339
336
}
340
337
}
341
338
339
+ uint64_t ThisVal = std::min (Offset, MaxSPChunk);
340
+
342
341
BuildStackAdjustment (MBB, MBBI, DL, isSub ? -ThisVal : ThisVal, InEpilogue)
343
342
.setMIFlag (Flag);
344
343
@@ -445,7 +444,7 @@ int64_t X86FrameLowering::mergeSPUpdates(MachineBasicBlock &MBB,
445
444
return CalcNewOffset (0 );
446
445
447
446
FoundStackAdjust (PI, Offset);
448
- if (std::abs ((int64_t )CalcNewOffset (Offset)) < MaxSPChunk)
447
+ if (( uint64_t ) std::abs ((int64_t )CalcNewOffset (Offset)) < MaxSPChunk)
449
448
break ;
450
449
451
450
if (doMergeWithPrevious ? (PI == MBB.begin ()) : (PI == MBB.end ()))
0 commit comments