Skip to content

Commit 9496c4e

Browse files
author
git apple-llvm automerger
committed
Merge commit 'e5fb86e1c8ef' from apple/master into swift/master-next
2 parents c95221e + e5fb86e commit 9496c4e

File tree

4 files changed

+295
-26
lines changed

4 files changed

+295
-26
lines changed

clang/test/CodeGen/ms-inline-asm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ void mxcsr() {
752752
__asm fxrstor buf
753753
}
754754
// CHECK-LABEL: define void @mxcsr
755-
// CHECK: call void asm sideeffect inteldialect "fxrstor $0", "=*m,~{dirflag},~{fpsr},~{flags}"
755+
// CHECK: call void asm sideeffect inteldialect "fxrstor $0", "=*m,~{fpcr},~{dirflag},~{fpsr},~{flags}"
756756

757757
// Make sure we can find the register for the dirflag for popfd
758758
void dirflag() {

llvm/lib/Target/X86/X86InstrFPStack.td

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def _FI32m : FPI<0xDA, fp, (outs), (ins i32mem:$src),
282282
!strconcat("fi", asmstring, "{l}\t$src")>;
283283
}
284284

285-
let Defs = [FPSW], Uses = [FPCW] in {
285+
let Uses = [FPCW], mayRaiseFPException = 1 in {
286286
// FPBinary_rr just defines pseudo-instructions, no need to set a scheduling
287287
// resources.
288288
let hasNoSchedulingInfo = 1 in {
@@ -307,7 +307,7 @@ let SchedRW = [WriteFDivLd] in {
307307
defm DIV : FPBinary<fdiv, MRM6m, "div">;
308308
defm DIVR: FPBinary<fdiv, MRM7m, "divr", 0>;
309309
}
310-
} // Defs = [FPSW]
310+
} // Uses = [FPCW], mayRaiseFPException = 1
311311

312312
class FPST0rInst<Format fp, string asm>
313313
: FPI<0xD8, fp, (outs), (ins RSTi:$op), asm>;
@@ -319,7 +319,7 @@ class FPrST0PInst<Format fp, string asm>
319319
// NOTE: GAS and apparently all other AT&T style assemblers have a broken notion
320320
// of some of the 'reverse' forms of the fsub and fdiv instructions. As such,
321321
// we have to put some 'r's in and take them out of weird places.
322-
let SchedRW = [WriteFAdd], Defs = [FPSW], Uses = [FPCW] in {
322+
let SchedRW = [WriteFAdd], Uses = [FPCW], mayRaiseFPException = 1 in {
323323
def ADD_FST0r : FPST0rInst <MRM0r, "fadd\t{$op, %st|st, $op}">;
324324
def ADD_FrST0 : FPrST0Inst <MRM0r, "fadd\t{%st, $op|$op, st}">;
325325
def ADD_FPrST0 : FPrST0PInst<MRM0r, "faddp\t{%st, $op|$op, st}">;
@@ -330,16 +330,16 @@ def SUB_FST0r : FPST0rInst <MRM4r, "fsub\t{$op, %st|st, $op}">;
330330
def SUBR_FrST0 : FPrST0Inst <MRM4r, "fsub{|r}\t{%st, $op|$op, st}">;
331331
def SUBR_FPrST0 : FPrST0PInst<MRM4r, "fsub{|r}p\t{%st, $op|$op, st}">;
332332
} // SchedRW
333-
let SchedRW = [WriteFCom], Defs = [FPSW], Uses = [FPCW] in {
333+
let SchedRW = [WriteFCom], Uses = [FPCW], mayRaiseFPException = 1 in {
334334
def COM_FST0r : FPST0rInst <MRM2r, "fcom\t$op">;
335335
def COMP_FST0r : FPST0rInst <MRM3r, "fcomp\t$op">;
336336
} // SchedRW
337-
let SchedRW = [WriteFMul], Defs = [FPSW], Uses = [FPCW] in {
337+
let SchedRW = [WriteFMul], Uses = [FPCW], mayRaiseFPException = 1 in {
338338
def MUL_FST0r : FPST0rInst <MRM1r, "fmul\t{$op, %st|st, $op}">;
339339
def MUL_FrST0 : FPrST0Inst <MRM1r, "fmul\t{%st, $op|$op, st}">;
340340
def MUL_FPrST0 : FPrST0PInst<MRM1r, "fmulp\t{%st, $op|$op, st}">;
341341
} // SchedRW
342-
let SchedRW = [WriteFDiv], Defs = [FPSW], Uses = [FPCW] in {
342+
let SchedRW = [WriteFDiv], Uses = [FPCW], mayRaiseFPException = 1 in {
343343
def DIVR_FST0r : FPST0rInst <MRM7r, "fdivr\t{$op, %st|st, $op}">;
344344
def DIV_FrST0 : FPrST0Inst <MRM7r, "fdiv{r}\t{%st, $op|$op, st}">;
345345
def DIV_FPrST0 : FPrST0PInst<MRM7r, "fdiv{r}p\t{%st, $op|$op, st}">;
@@ -359,13 +359,12 @@ def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src), OneArgFPRW,
359359
def _F : FPI<0xD9, fp, (outs), (ins), asmstring>;
360360
}
361361

362-
let Defs = [FPSW], Uses = [FPCW] in {
363-
364362
let SchedRW = [WriteFSign] in {
365363
defm CHS : FPUnary<fneg, MRM_E0, "fchs">;
366364
defm ABS : FPUnary<fabs, MRM_E1, "fabs">;
367365
}
368366

367+
let Uses = [FPCW], mayRaiseFPException = 1 in {
369368
let SchedRW = [WriteFSqrt80] in
370369
defm SQRT: FPUnary<fsqrt,MRM_FA, "fsqrt">;
371370

@@ -378,11 +377,11 @@ def TST_Fp80 : FpI_<(outs), (ins RFP80:$src), OneArgFP, []>;
378377

379378
def TST_F : FPI<0xD9, MRM_E4, (outs), (ins), "ftst">;
380379
} // SchedRW
381-
} // Defs = [FPSW]
380+
} // Uses = [FPCW], mayRaiseFPException = 1
382381

383382
// Versions of FP instructions that take a single memory operand. Added for the
384383
// disassembler; remove as they are included with patterns elsewhere.
385-
let SchedRW = [WriteFComLd], Defs = [FPSW], Uses = [FPCW] in {
384+
let SchedRW = [WriteFComLd], Uses = [FPCW], mayRaiseFPException = 1 in {
386385
def FCOM32m : FPI<0xD8, MRM2m, (outs), (ins f32mem:$src), "fcom{s}\t$src">;
387386
def FCOMP32m : FPI<0xD8, MRM3m, (outs), (ins f32mem:$src), "fcomp{s}\t$src">;
388387

@@ -397,14 +396,21 @@ def FICOMP32m: FPI<0xDA, MRM3m, (outs), (ins i32mem:$src), "ficomp{l}\t$src">;
397396
} // SchedRW
398397

399398
let SchedRW = [WriteMicrocoded] in {
399+
let Defs = [FPSW, FPCW] in {
400400
def FLDENVm : FPI<0xD9, MRM4m, (outs), (ins f32mem:$src), "fldenv\t$src">;
401-
def FSTENVm : FPI<0xD9, MRM6m, (outs), (ins f32mem:$dst), "fnstenv\t$dst">;
402-
403401
def FRSTORm : FPI<0xDD, MRM4m, (outs), (ins f32mem:$dst), "frstor\t$dst">;
402+
}
403+
404+
let Defs = [FPSW, FPCW], Uses = [FPSW, FPCW] in {
405+
def FSTENVm : FPI<0xD9, MRM6m, (outs), (ins f32mem:$dst), "fnstenv\t$dst">;
404406
def FSAVEm : FPI<0xDD, MRM6m, (outs), (ins f32mem:$dst), "fnsave\t$dst">;
407+
}
408+
409+
let Uses = [FPSW] in
405410
def FNSTSWm : FPI<0xDD, MRM7m, (outs), (ins i16mem:$dst), "fnstsw\t$dst">;
406411

407412
def FBLDm : FPI<0xDF, MRM4m, (outs), (ins f80mem:$src), "fbld\t$src">;
413+
let Uses = [FPCW] ,mayRaiseFPException = 1 in
408414
def FBSTPm : FPI<0xDF, MRM6m, (outs), (ins f80mem:$dst), "fbstp\t$dst">;
409415
} // SchedRW
410416

@@ -430,7 +436,6 @@ multiclass FPCMov<PatLeaf cc> {
430436
Requires<[HasCMov]>;
431437
}
432438

433-
let Defs = [FPSW] in {
434439
let SchedRW = [WriteFCMOV] in {
435440
let Uses = [EFLAGS], Constraints = "$src1 = $dst" in {
436441
defm CMOVB : FPCMov<X86_COND_B>;
@@ -464,6 +469,7 @@ def CMOVNP_F : FPI<0xDB, MRM3r, (outs), (ins RSTi:$op),
464469
} // Predicates = [HasCMov]
465470
} // SchedRW
466471

472+
let mayRaiseFPException = 1 in {
467473
// Floating point loads & stores.
468474
let SchedRW = [WriteLoad], Uses = [FPCW] in {
469475
let canFoldAsLoad = 1 in {
@@ -480,6 +486,7 @@ def LD_Fp64m80 : FpI_<(outs RFP80:$dst), (ins f64mem:$src), ZeroArgFP,
480486
[(set RFP80:$dst, (f80 (extloadf64 addr:$src)))]>;
481487
def LD_Fp32m80 : FpI_<(outs RFP80:$dst), (ins f32mem:$src), ZeroArgFP,
482488
[(set RFP80:$dst, (f80 (extloadf32 addr:$src)))]>;
489+
let mayRaiseFPException = 0 in {
483490
def ILD_Fp16m32: FpIf32<(outs RFP32:$dst), (ins i16mem:$src), ZeroArgFP,
484491
[(set RFP32:$dst, (X86fild16 addr:$src))]>;
485492
def ILD_Fp32m32: FpIf32<(outs RFP32:$dst), (ins i32mem:$src), ZeroArgFP,
@@ -498,6 +505,7 @@ def ILD_Fp32m80: FpI_<(outs RFP80:$dst), (ins i32mem:$src), ZeroArgFP,
498505
[(set RFP80:$dst, (X86fild32 addr:$src))]>;
499506
def ILD_Fp64m80: FpI_<(outs RFP80:$dst), (ins i64mem:$src), ZeroArgFP,
500507
[(set RFP80:$dst, (X86fild64 addr:$src))]>;
508+
} // mayRaiseFPException = 0
501509
} // SchedRW
502510

503511
let SchedRW = [WriteStore], Uses = [FPCW] in {
@@ -541,10 +549,12 @@ let mayLoad = 1, SchedRW = [WriteLoad], Uses = [FPCW] in {
541549
def LD_F32m : FPI<0xD9, MRM0m, (outs), (ins f32mem:$src), "fld{s}\t$src">;
542550
def LD_F64m : FPI<0xDD, MRM0m, (outs), (ins f64mem:$src), "fld{l}\t$src">;
543551
def LD_F80m : FPI<0xDB, MRM5m, (outs), (ins f80mem:$src), "fld{t}\t$src">;
552+
let mayRaiseFPException = 0 in {
544553
def ILD_F16m : FPI<0xDF, MRM0m, (outs), (ins i16mem:$src), "fild{s}\t$src">;
545554
def ILD_F32m : FPI<0xDB, MRM0m, (outs), (ins i32mem:$src), "fild{l}\t$src">;
546555
def ILD_F64m : FPI<0xDF, MRM5m, (outs), (ins i64mem:$src), "fild{ll}\t$src">;
547556
}
557+
}
548558
let mayStore = 1, SchedRW = [WriteStore], Uses = [FPCW] in {
549559
def ST_F32m : FPI<0xD9, MRM2m, (outs), (ins f32mem:$dst), "fst{s}\t$dst">;
550560
def ST_F64m : FPI<0xDD, MRM2m, (outs), (ins f64mem:$dst), "fst{l}\t$dst">;
@@ -616,7 +626,7 @@ def LD_F0 : FPI<0xD9, MRM_EE, (outs), (ins), "fldz">;
616626
let SchedRW = [WriteFLD1], Uses = [FPCW] in
617627
def LD_F1 : FPI<0xD9, MRM_E8, (outs), (ins), "fld1">;
618628

619-
let SchedRW = [WriteFLDC], Uses = [FPCW] in {
629+
let SchedRW = [WriteFLDC], Defs = [FPSW], Uses = [FPCW] in {
620630
def FLDL2T : I<0xD9, MRM_E9, (outs), (ins), "fldl2t", []>;
621631
def FLDL2E : I<0xD9, MRM_EA, (outs), (ins), "fldl2e", []>;
622632
def FLDPI : I<0xD9, MRM_EB, (outs), (ins), "fldpi", []>;
@@ -633,11 +643,11 @@ def UCOM_Fpr64 : FpIf64<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
633643
def UCOM_Fpr80 : FpI_ <(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP,
634644
[(set FPSW, (trunc (X86cmp RFP80:$lhs, RFP80:$rhs)))]>;
635645
} // SchedRW
636-
} // Defs = [FPSW]
646+
} // mayRaiseFPException = 1
637647

638-
let SchedRW = [WriteFCom] in {
648+
let SchedRW = [WriteFCom], mayRaiseFPException = 1 in {
639649
// CC = ST(0) cmp ST(i)
640-
let Defs = [EFLAGS, FPSW], Uses = [FPCW] in {
650+
let Defs = [EFLAGS, FPCW], Uses = [FPCW] in {
641651
def UCOM_FpIr32: FpI_<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP,
642652
[(set EFLAGS, (X86cmp RFP32:$lhs, RFP32:$rhs))]>,
643653
Requires<[FPStackf32, HasCMov]>;
@@ -649,7 +659,7 @@ def UCOM_FpIr80: FpI_<(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP,
649659
Requires<[HasCMov]>;
650660
}
651661

652-
let Defs = [FPSW], Uses = [ST0, FPCW] in {
662+
let Uses = [ST0, FPCW] in {
653663
def UCOM_Fr : FPI<0xDD, MRM4r, // FPSW = cmp ST(0) with ST(i)
654664
(outs), (ins RSTi:$reg), "fucom\t$reg">;
655665
def UCOM_FPr : FPI<0xDD, MRM5r, // FPSW = cmp ST(0) with ST(i), pop
@@ -673,7 +683,7 @@ def COM_FIPr : FPI<0xDF, MRM6r, (outs), (ins RSTi:$reg),
673683

674684
// Floating point flag ops.
675685
let SchedRW = [WriteALU] in {
676-
let Defs = [AX], Uses = [FPSW] in
686+
let Defs = [AX, FPSW], Uses = [FPSW] in
677687
def FNSTSW16r : I<0xDF, MRM_E0, // AX = fp flags
678688
(outs), (ins), "fnstsw\t{%ax|ax}",
679689
[(set AX, (X86fp_stsw FPSW))]>;
@@ -689,31 +699,33 @@ def FLDCW16m : I<0xD9, MRM5m, // X87 control world = [mem16]
689699

690700
// FPU control instructions
691701
let SchedRW = [WriteMicrocoded] in {
692-
let Defs = [FPSW] in {
693-
def FNINIT : I<0xDB, MRM_E3, (outs), (ins), "fninit", []>;
694702
def FFREE : FPI<0xDD, MRM0r, (outs), (ins RSTi:$reg), "ffree\t$reg">;
695703
def FFREEP : FPI<0xDF, MRM0r, (outs), (ins RSTi:$reg), "ffreep\t$reg">;
696704

705+
let Defs = [FPSW, FPCW] in
706+
def FNINIT : I<0xDB, MRM_E3, (outs), (ins), "fninit", []>;
697707
// Clear exceptions
708+
let Defs = [FPSW] in
698709
def FNCLEX : I<0xDB, MRM_E2, (outs), (ins), "fnclex", []>;
699-
} // Defs = [FPSW]
700710
} // SchedRW
701711

702712
// Operand-less floating-point instructions for the disassembler.
713+
let Defs = [FPSW] in
703714
def FNOP : I<0xD9, MRM_D0, (outs), (ins), "fnop", []>, Sched<[WriteNop]>;
704715

705716
let SchedRW = [WriteMicrocoded] in {
706717
let Defs = [FPSW] in {
707718
def WAIT : I<0x9B, RawFrm, (outs), (ins), "wait", []>;
708719
def FXAM : I<0xD9, MRM_E5, (outs), (ins), "fxam", []>;
720+
def FDECSTP : I<0xD9, MRM_F6, (outs), (ins), "fdecstp", []>;
721+
def FINCSTP : I<0xD9, MRM_F7, (outs), (ins), "fincstp", []>;
722+
let Uses = [FPCW], mayRaiseFPException = 1 in {
709723
def F2XM1 : I<0xD9, MRM_F0, (outs), (ins), "f2xm1", []>;
710724
def FYL2X : I<0xD9, MRM_F1, (outs), (ins), "fyl2x", []>;
711725
def FPTAN : I<0xD9, MRM_F2, (outs), (ins), "fptan", []>;
712726
def FPATAN : I<0xD9, MRM_F3, (outs), (ins), "fpatan", []>;
713727
def FXTRACT : I<0xD9, MRM_F4, (outs), (ins), "fxtract", []>;
714728
def FPREM1 : I<0xD9, MRM_F5, (outs), (ins), "fprem1", []>;
715-
def FDECSTP : I<0xD9, MRM_F6, (outs), (ins), "fdecstp", []>;
716-
def FINCSTP : I<0xD9, MRM_F7, (outs), (ins), "fincstp", []>;
717729
def FPREM : I<0xD9, MRM_F8, (outs), (ins), "fprem", []>;
718730
def FYL2XP1 : I<0xD9, MRM_F9, (outs), (ins), "fyl2xp1", []>;
719731
def FSIN : I<0xD9, MRM_FE, (outs), (ins), "fsin", []>;
@@ -722,20 +734,26 @@ def FSINCOS : I<0xD9, MRM_FB, (outs), (ins), "fsincos", []>;
722734
def FRNDINT : I<0xD9, MRM_FC, (outs), (ins), "frndint", []>;
723735
def FSCALE : I<0xD9, MRM_FD, (outs), (ins), "fscale", []>;
724736
def FCOMPP : I<0xDE, MRM_D9, (outs), (ins), "fcompp", []>;
737+
} // Uses = [FPCW], mayRaiseFPException = 1
725738
} // Defs = [FPSW]
726739

740+
let Uses = [FPSW, FPCW] in {
727741
def FXSAVE : I<0xAE, MRM0m, (outs), (ins opaquemem:$dst),
728742
"fxsave\t$dst", [(int_x86_fxsave addr:$dst)]>, TB,
729743
Requires<[HasFXSR]>;
730744
def FXSAVE64 : RI<0xAE, MRM0m, (outs), (ins opaquemem:$dst),
731745
"fxsave64\t$dst", [(int_x86_fxsave64 addr:$dst)]>,
732746
TB, Requires<[HasFXSR, In64BitMode]>;
747+
} // Uses = [FPSW, FPCW]
748+
749+
let Defs = [FPSW, FPCW] in {
733750
def FXRSTOR : I<0xAE, MRM1m, (outs), (ins opaquemem:$src),
734751
"fxrstor\t$src", [(int_x86_fxrstor addr:$src)]>,
735752
TB, Requires<[HasFXSR]>;
736753
def FXRSTOR64 : RI<0xAE, MRM1m, (outs), (ins opaquemem:$src),
737754
"fxrstor64\t$src", [(int_x86_fxrstor64 addr:$src)]>,
738755
TB, Requires<[HasFXSR, In64BitMode]>;
756+
} // Defs = [FPSW, FPCW]
739757
} // SchedRW
740758

741759
//===----------------------------------------------------------------------===//

llvm/lib/Target/X86/X86InstrFormats.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,15 @@ class Ii32PCRel<bits<8> o, Format f, dag outs, dag ins, string asm,
442442
// FPStack Instruction Templates:
443443
// FPI - Floating Point Instruction template.
444444
class FPI<bits<8> o, Format F, dag outs, dag ins, string asm>
445-
: I<o, F, outs, ins, asm, []> {}
445+
: I<o, F, outs, ins, asm, []> {
446+
let Defs = [FPSW];
447+
}
446448

447449
// FpI_ - Floating Point Pseudo Instruction template. Not Predicated.
448450
class FpI_<dag outs, dag ins, FPFormat fp, list<dag> pattern>
449451
: PseudoI<outs, ins, pattern> {
450452
let FPForm = fp;
453+
let Defs = [FPSW];
451454
}
452455

453456
// Templates for instructions that use a 16- or 32-bit segmented address as

0 commit comments

Comments
 (0)