Skip to content

Commit 1506fb7

Browse files
committed
[X86] Stop emitting CFI instructions on i386-windows
`X86FrameLowering` normally emits CFI instructions when `needsDwarfCFI` returns true. Before this patch it was assumed that this method returns true on non-Windows target, but it also returns true on Windows i386, which results in erroneous generation of CFI instructions on that platform. This behavior cannot be observed in the generated assembly because AsmPrinter suppresses printing of these instructions for WinEH exception model. I'm going to change this: the idea is that if a target has created a CFI instruction, it should be printed. If it should not be printed, it should not have been created in the first place. There was a couple of places where `needsDwarfCFI` wasn't used, also resulting in erroneous generation of CFI instruction. Now fixed as well. The changes in tests seem to be caused by `SlotIndexes` assigning different numbers to instructions, which affects live range lengths and consequently the register allocator heuristics.
1 parent ebba554 commit 1506fb7

File tree

11 files changed

+247
-257
lines changed

11 files changed

+247
-257
lines changed

llvm/lib/Target/X86/X86CallFrameOptimization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ void X86CallFrameOptimization::adjustCallSequence(MachineFunction &MF,
570570
// For debugging, when using SP-based CFA, we need to adjust the CFA
571571
// offset after each push.
572572
// TODO: This is needed only if we require precise CFA.
573-
if (!TFL->hasFP(MF))
573+
if (TFL->needsDwarfCFI(MF) && !TFL->hasFP(MF))
574574
TFL->BuildCFI(
575575
MBB, std::next(Push), DL,
576576
MCCFIInstruction::createAdjustCfaOffset(nullptr, SlotSize));

llvm/lib/Target/X86/X86FrameLowering.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,9 @@ bool X86FrameLowering::isWin64Prologue(const MachineFunction &MF) const {
14681468
}
14691469

14701470
bool X86FrameLowering::needsDwarfCFI(const MachineFunction &MF) const {
1471-
return !isWin64Prologue(MF) && MF.needsFrameMoves();
1471+
return MF.getTarget().getMCAsmInfo()->getExceptionHandlingType() !=
1472+
ExceptionHandling::WinEH &&
1473+
MF.needsFrameMoves();
14721474
}
14731475

14741476
/// Return true if an opcode is part of the REP group of instructions
@@ -3808,8 +3810,7 @@ MachineBasicBlock::iterator X86FrameLowering::eliminateCallFramePseudoInstr(
38083810
Amount = alignTo(Amount, getStackAlign());
38093811

38103812
const Function &F = MF.getFunction();
3811-
bool WindowsCFI = MF.getTarget().getMCAsmInfo()->usesWindowsCFI();
3812-
bool DwarfCFI = !WindowsCFI && MF.needsFrameMoves();
3813+
bool DwarfCFI = needsDwarfCFI(MF);
38133814

38143815
// If we have any exception handlers in this function, and we adjust
38153816
// the SP before calls, we may need to indicate this to the unwinder
@@ -3818,7 +3819,7 @@ MachineBasicBlock::iterator X86FrameLowering::eliminateCallFramePseudoInstr(
38183819
// GNU_ARGS_SIZE.
38193820
// TODO: We don't need to reset this between subsequent functions,
38203821
// if it didn't change.
3821-
bool HasDwarfEHHandlers = !WindowsCFI && !MF.getLandingPads().empty();
3822+
bool HasDwarfEHHandlers = DwarfCFI && !MF.getLandingPads().empty();
38223823

38233824
if (HasDwarfEHHandlers && !isDestroy &&
38243825
MF.getInfo<X86MachineFunctionInfo>()->getHasPushSequences())

llvm/lib/Target/X86/X86FrameLowering.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ class X86FrameLowering : public TargetFrameLowering {
238238
/// frame of the top of stack function) as part of it's ABI.
239239
bool has128ByteRedZone(const MachineFunction& MF) const;
240240

241+
bool needsDwarfCFI(const MachineFunction &MF) const;
242+
241243
protected:
242244
bool hasFPImpl(const MachineFunction &MF) const override;
243245

244246
private:
245247
bool isWin64Prologue(const MachineFunction &MF) const;
246248

247-
bool needsDwarfCFI(const MachineFunction &MF) const;
248-
249249
uint64_t calculateMaxStackAlign(const MachineFunction &MF) const;
250250

251251
/// Emit target stack probe as a call to a helper function

llvm/test/CodeGen/MIR/X86/diexpr-win32.mir

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,6 @@ body: |
190190
liveins: $esi
191191
192192
frame-setup PUSH32r killed $esi, implicit-def $esp, implicit $esp
193-
CFI_INSTRUCTION def_cfa_offset 8
194-
CFI_INSTRUCTION offset $esi, -8
195193
$esi = MOV32rm $esp, 1, _, 8, _ :: (load (s32) from %fixed-stack.2)
196194
DBG_VALUE $esp, 0, !26, !10, debug-location !25
197195
DBG_VALUE $esp, 0, !23, !DIExpression(DW_OP_plus_uconst, 8, DW_OP_deref), debug-location !25

llvm/test/CodeGen/X86/2008-04-16-ReMatBug.ll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ define i16 @SQLDriversW(ptr %henv, i16 zeroext %fDir, ptr %szDrvDesc, i16 signe
2828
; CHECK-NEXT: ## %bb.4: ## %bb37
2929
; CHECK-NEXT: movw $0, 40(%edi)
3030
; CHECK-NEXT: testb %al, %al
31-
; CHECK-NEXT: leal (,%ecx,4), %ecx
32-
; CHECK-NEXT: leal (,%ebx,4), %edx
31+
; CHECK-NEXT: leal (,%ecx,4), %eax
32+
; CHECK-NEXT: leal (,%ebx,4), %ecx
3333
; CHECK-NEXT: subl $12, %esp
34-
; CHECK-NEXT: movzwl %bp, %eax
34+
; CHECK-NEXT: movzwl %bp, %edx
35+
; CHECK-NEXT: cwtl
3536
; CHECK-NEXT: movswl %cx, %ecx
36-
; CHECK-NEXT: movswl %dx, %edx
3737
; CHECK-NEXT: pushl $87
3838
; CHECK-NEXT: pushl {{[0-9]+}}(%esp)
39-
; CHECK-NEXT: pushl %ecx
39+
; CHECK-NEXT: pushl %eax
4040
; CHECK-NEXT: pushl $0
4141
; CHECK-NEXT: pushl {{[0-9]+}}(%esp)
42-
; CHECK-NEXT: pushl %edx
42+
; CHECK-NEXT: pushl %ecx
4343
; CHECK-NEXT: pushl $0
44-
; CHECK-NEXT: pushl %eax
44+
; CHECK-NEXT: pushl %edx
4545
; CHECK-NEXT: pushl %edi
4646
; CHECK-NEXT: calll _SQLDrivers_Internal
4747
; CHECK-NEXT: addl $48, %esp

llvm/test/CodeGen/X86/andnot-patterns.ll

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,28 +198,28 @@ define i64 @andnot_rotl_i64_multiuse_rot(i64 %a0, i64 %a1, i64 %a2) nounwind {
198198
; X86-NEXT: pushl %esi
199199
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
200200
; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
201-
; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
202-
; X86-NEXT: notl %edx
201+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
202+
; X86-NEXT: notl %eax
203203
; X86-NEXT: notl %esi
204204
; X86-NEXT: testb $32, %cl
205205
; X86-NEXT: jne .LBB4_1
206206
; X86-NEXT: # %bb.2:
207-
; X86-NEXT: movl %esi, %eax
207+
; X86-NEXT: movl %esi, %edx
208208
; X86-NEXT: jmp .LBB4_3
209209
; X86-NEXT: .LBB4_1:
210-
; X86-NEXT: movl %edx, %eax
211-
; X86-NEXT: movl %esi, %edx
210+
; X86-NEXT: movl %eax, %edx
211+
; X86-NEXT: movl %esi, %eax
212212
; X86-NEXT: .LBB4_3:
213-
; X86-NEXT: movl %edx, %ebx
214-
; X86-NEXT: shldl %cl, %eax, %ebx
213+
; X86-NEXT: movl %eax, %ebx
214+
; X86-NEXT: shldl %cl, %edx, %ebx
215215
; X86-NEXT: # kill: def $cl killed $cl killed $ecx
216-
; X86-NEXT: shldl %cl, %edx, %eax
216+
; X86-NEXT: shldl %cl, %eax, %edx
217217
; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
218-
; X86-NEXT: andl %eax, %esi
218+
; X86-NEXT: andl %edx, %esi
219219
; X86-NEXT: movl {{[0-9]+}}(%esp), %edi
220220
; X86-NEXT: andl %ebx, %edi
221221
; X86-NEXT: pushl %ebx
222-
; X86-NEXT: pushl %eax
222+
; X86-NEXT: pushl %edx
223223
; X86-NEXT: calll use_i64@PLT
224224
; X86-NEXT: addl $8, %esp
225225
; X86-NEXT: movl %esi, %eax

llvm/test/CodeGen/X86/fp128-cast.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,19 +1139,19 @@ define dso_local i32 @TestBits128(fp128 %ld) nounwind {
11391139
; X86-NEXT: subl $20, %esp
11401140
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
11411141
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
1142+
; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
11421143
; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
1143-
; X86-NEXT: movl {{[0-9]+}}(%esp), %edi
11441144
; X86-NEXT: subl $12, %esp
1145-
; X86-NEXT: leal {{[0-9]+}}(%esp), %edx
1146-
; X86-NEXT: pushl %edi
1145+
; X86-NEXT: leal {{[0-9]+}}(%esp), %edi
11471146
; X86-NEXT: pushl %esi
1147+
; X86-NEXT: pushl %edx
11481148
; X86-NEXT: pushl %ecx
11491149
; X86-NEXT: pushl %eax
1150-
; X86-NEXT: pushl %edi
11511150
; X86-NEXT: pushl %esi
1151+
; X86-NEXT: pushl %edx
11521152
; X86-NEXT: pushl %ecx
11531153
; X86-NEXT: pushl %eax
1154-
; X86-NEXT: pushl %edx
1154+
; X86-NEXT: pushl %edi
11551155
; X86-NEXT: calll __multf3
11561156
; X86-NEXT: addl $44, %esp
11571157
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx

llvm/test/CodeGen/X86/fp128-libcalls-strict.ll

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3418,28 +3418,28 @@ define i64 @cmp_ueq_q(i64 %a, i64 %b, fp128 %x, fp128 %y) #0 {
34183418
; X86-NEXT: pushl %edi
34193419
; X86-NEXT: pushl %esi
34203420
; X86-NEXT: subl $12, %esp
3421-
; X86-NEXT: movl {{[0-9]+}}(%esp), %ebp
34223421
; X86-NEXT: movl {{[0-9]+}}(%esp), %edi
34233422
; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
3423+
; X86-NEXT: movl {{[0-9]+}}(%esp), %ebp
3424+
; X86-NEXT: pushl %ebp
34243425
; X86-NEXT: pushl {{[0-9]+}}(%esp)
34253426
; X86-NEXT: pushl {{[0-9]+}}(%esp)
34263427
; X86-NEXT: pushl {{[0-9]+}}(%esp)
34273428
; X86-NEXT: pushl {{[0-9]+}}(%esp)
34283429
; X86-NEXT: pushl %esi
34293430
; X86-NEXT: pushl %edi
3430-
; X86-NEXT: pushl %ebp
34313431
; X86-NEXT: pushl {{[0-9]+}}(%esp)
34323432
; X86-NEXT: calll __eqtf2
34333433
; X86-NEXT: addl $32, %esp
34343434
; X86-NEXT: testl %eax, %eax
34353435
; X86-NEXT: sete %bl
3436+
; X86-NEXT: pushl %ebp
34363437
; X86-NEXT: pushl {{[0-9]+}}(%esp)
34373438
; X86-NEXT: pushl {{[0-9]+}}(%esp)
34383439
; X86-NEXT: pushl {{[0-9]+}}(%esp)
34393440
; X86-NEXT: pushl {{[0-9]+}}(%esp)
34403441
; X86-NEXT: pushl %esi
34413442
; X86-NEXT: pushl %edi
3442-
; X86-NEXT: pushl %ebp
34433443
; X86-NEXT: pushl {{[0-9]+}}(%esp)
34443444
; X86-NEXT: calll __unordtf2
34453445
; X86-NEXT: addl $32, %esp
@@ -3501,28 +3501,28 @@ define i64 @cmp_ueq_q(i64 %a, i64 %b, fp128 %x, fp128 %y) #0 {
35013501
; WIN-X86-NEXT: pushl %ebx
35023502
; WIN-X86-NEXT: pushl %edi
35033503
; WIN-X86-NEXT: pushl %esi
3504-
; WIN-X86-NEXT: movl {{[0-9]+}}(%esp), %ebp
35053504
; WIN-X86-NEXT: movl {{[0-9]+}}(%esp), %edi
35063505
; WIN-X86-NEXT: movl {{[0-9]+}}(%esp), %esi
3506+
; WIN-X86-NEXT: movl {{[0-9]+}}(%esp), %ebp
3507+
; WIN-X86-NEXT: pushl %ebp
35073508
; WIN-X86-NEXT: pushl {{[0-9]+}}(%esp)
35083509
; WIN-X86-NEXT: pushl {{[0-9]+}}(%esp)
35093510
; WIN-X86-NEXT: pushl {{[0-9]+}}(%esp)
35103511
; WIN-X86-NEXT: pushl {{[0-9]+}}(%esp)
35113512
; WIN-X86-NEXT: pushl %esi
35123513
; WIN-X86-NEXT: pushl %edi
3513-
; WIN-X86-NEXT: pushl %ebp
35143514
; WIN-X86-NEXT: pushl {{[0-9]+}}(%esp)
35153515
; WIN-X86-NEXT: calll ___eqtf2
35163516
; WIN-X86-NEXT: addl $32, %esp
35173517
; WIN-X86-NEXT: testl %eax, %eax
35183518
; WIN-X86-NEXT: sete %bl
3519+
; WIN-X86-NEXT: pushl %ebp
35193520
; WIN-X86-NEXT: pushl {{[0-9]+}}(%esp)
35203521
; WIN-X86-NEXT: pushl {{[0-9]+}}(%esp)
35213522
; WIN-X86-NEXT: pushl {{[0-9]+}}(%esp)
35223523
; WIN-X86-NEXT: pushl {{[0-9]+}}(%esp)
35233524
; WIN-X86-NEXT: pushl %esi
35243525
; WIN-X86-NEXT: pushl %edi
3525-
; WIN-X86-NEXT: pushl %ebp
35263526
; WIN-X86-NEXT: pushl {{[0-9]+}}(%esp)
35273527
; WIN-X86-NEXT: calll ___unordtf2
35283528
; WIN-X86-NEXT: addl $32, %esp
@@ -3640,28 +3640,28 @@ define i64 @cmp_one_q(i64 %a, i64 %b, fp128 %x, fp128 %y) #0 {
36403640
; X86-NEXT: pushl %edi
36413641
; X86-NEXT: pushl %esi
36423642
; X86-NEXT: subl $12, %esp
3643-
; X86-NEXT: movl {{[0-9]+}}(%esp), %ebp
36443643
; X86-NEXT: movl {{[0-9]+}}(%esp), %edi
36453644
; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
3645+
; X86-NEXT: movl {{[0-9]+}}(%esp), %ebp
3646+
; X86-NEXT: pushl %ebp
36463647
; X86-NEXT: pushl {{[0-9]+}}(%esp)
36473648
; X86-NEXT: pushl {{[0-9]+}}(%esp)
36483649
; X86-NEXT: pushl {{[0-9]+}}(%esp)
36493650
; X86-NEXT: pushl {{[0-9]+}}(%esp)
36503651
; X86-NEXT: pushl %esi
36513652
; X86-NEXT: pushl %edi
3652-
; X86-NEXT: pushl %ebp
36533653
; X86-NEXT: pushl {{[0-9]+}}(%esp)
36543654
; X86-NEXT: calll __eqtf2
36553655
; X86-NEXT: addl $32, %esp
36563656
; X86-NEXT: testl %eax, %eax
36573657
; X86-NEXT: setne %bl
3658+
; X86-NEXT: pushl %ebp
36583659
; X86-NEXT: pushl {{[0-9]+}}(%esp)
36593660
; X86-NEXT: pushl {{[0-9]+}}(%esp)
36603661
; X86-NEXT: pushl {{[0-9]+}}(%esp)
36613662
; X86-NEXT: pushl {{[0-9]+}}(%esp)
36623663
; X86-NEXT: pushl %esi
36633664
; X86-NEXT: pushl %edi
3664-
; X86-NEXT: pushl %ebp
36653665
; X86-NEXT: pushl {{[0-9]+}}(%esp)
36663666
; X86-NEXT: calll __unordtf2
36673667
; X86-NEXT: addl $32, %esp
@@ -3723,28 +3723,28 @@ define i64 @cmp_one_q(i64 %a, i64 %b, fp128 %x, fp128 %y) #0 {
37233723
; WIN-X86-NEXT: pushl %ebx
37243724
; WIN-X86-NEXT: pushl %edi
37253725
; WIN-X86-NEXT: pushl %esi
3726-
; WIN-X86-NEXT: movl {{[0-9]+}}(%esp), %ebp
37273726
; WIN-X86-NEXT: movl {{[0-9]+}}(%esp), %edi
37283727
; WIN-X86-NEXT: movl {{[0-9]+}}(%esp), %esi
3728+
; WIN-X86-NEXT: movl {{[0-9]+}}(%esp), %ebp
3729+
; WIN-X86-NEXT: pushl %ebp
37293730
; WIN-X86-NEXT: pushl {{[0-9]+}}(%esp)
37303731
; WIN-X86-NEXT: pushl {{[0-9]+}}(%esp)
37313732
; WIN-X86-NEXT: pushl {{[0-9]+}}(%esp)
37323733
; WIN-X86-NEXT: pushl {{[0-9]+}}(%esp)
37333734
; WIN-X86-NEXT: pushl %esi
37343735
; WIN-X86-NEXT: pushl %edi
3735-
; WIN-X86-NEXT: pushl %ebp
37363736
; WIN-X86-NEXT: pushl {{[0-9]+}}(%esp)
37373737
; WIN-X86-NEXT: calll ___eqtf2
37383738
; WIN-X86-NEXT: addl $32, %esp
37393739
; WIN-X86-NEXT: testl %eax, %eax
37403740
; WIN-X86-NEXT: setne %bl
3741+
; WIN-X86-NEXT: pushl %ebp
37413742
; WIN-X86-NEXT: pushl {{[0-9]+}}(%esp)
37423743
; WIN-X86-NEXT: pushl {{[0-9]+}}(%esp)
37433744
; WIN-X86-NEXT: pushl {{[0-9]+}}(%esp)
37443745
; WIN-X86-NEXT: pushl {{[0-9]+}}(%esp)
37453746
; WIN-X86-NEXT: pushl %esi
37463747
; WIN-X86-NEXT: pushl %edi
3747-
; WIN-X86-NEXT: pushl %ebp
37483748
; WIN-X86-NEXT: pushl {{[0-9]+}}(%esp)
37493749
; WIN-X86-NEXT: calll ___unordtf2
37503750
; WIN-X86-NEXT: addl $32, %esp

0 commit comments

Comments
 (0)