Index: lib/CodeGen/SelectionDAG/SelectionDAG.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -4818,7 +4818,7 @@ case ISD::FMUL: case ISD::FDIV: case ISD::FREM: - if (getTarget().Options.UnsafeFPMath) + if (getTarget().Options.UnsafeFPMath || Flags.isFast()) return N2; break; case ISD::MUL: Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -2769,6 +2769,10 @@ Flags.setVectorReduction(true); LLVM_DEBUG(dbgs() << "Detected a reduction operation:" << I << "\n"); } + // need Flags for Selection DAG decisions here + if (auto *FPMO = dyn_cast(&I)) { + Flags.copyFMF(*FPMO); + } SDValue Op1 = getValue(I.getOperand(0)); SDValue Op2 = getValue(I.getOperand(1)); Index: test/CodeGen/X86/fp-undef.ll =================================================================== --- test/CodeGen/X86/fp-undef.ll +++ test/CodeGen/X86/fp-undef.ll @@ -6,28 +6,18 @@ ; adding something here, you should probably add it there too. define float @fadd_undef_op0(float %x) { -; STRICT-LABEL: fadd_undef_op0: -; STRICT: # %bb.0: -; STRICT-NEXT: addss %xmm0, %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fadd_undef_op0: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq - %r = fadd float undef, %x +; ANY-LABEL: fadd_undef_op0: +; ANY: # %bb.0: +; ANY-NEXT: retq + %r = fadd fast float undef, %x ret float %r } define float @fadd_undef_op1(float %x) { -; STRICT-LABEL: fadd_undef_op1: -; STRICT: # %bb.0: -; STRICT-NEXT: addss %xmm0, %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fadd_undef_op1: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq - %r = fadd float %x, undef +; ANY-LABEL: fadd_undef_op1: +; ANY: # %bb.0: +; ANY-NEXT: retq + %r = fadd fast float %x, undef ret float %r } @@ -35,46 +25,31 @@ ; ANY-LABEL: fsub_undef_op0: ; ANY: # %bb.0: ; ANY-NEXT: retq - %r = fsub float undef, %x + %r = fsub fast float undef, %x ret float %r } define float @fsub_undef_op1(float %x) { -; STRICT-LABEL: fsub_undef_op1: -; STRICT: # %bb.0: -; STRICT-NEXT: subss %xmm0, %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fsub_undef_op1: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq - %r = fsub float %x, undef +; ANY-LABEL: fsub_undef_op1: +; ANY: # %bb.0: +; ANY-NEXT: retq + %r = fsub fast float %x, undef ret float %r } define float @fmul_undef_op0(float %x) { -; STRICT-LABEL: fmul_undef_op0: -; STRICT: # %bb.0: -; STRICT-NEXT: mulss %xmm0, %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fmul_undef_op0: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq - %r = fmul float undef, %x +; ANY-LABEL: fmul_undef_op0: +; ANY: # %bb.0: +; ANY-NEXT: retq + %r = fmul fast float undef, %x ret float %r } define float @fmul_undef_op1(float %x) { -; STRICT-LABEL: fmul_undef_op1: -; STRICT: # %bb.0: -; STRICT-NEXT: mulss %xmm0, %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fmul_undef_op1: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq - %r = fmul float %x, undef +; ANY-LABEL: fmul_undef_op1: +; ANY: # %bb.0: +; ANY-NEXT: retq + %r = fmul fast float %x, undef ret float %r } @@ -82,20 +57,15 @@ ; ANY-LABEL: fdiv_undef_op0: ; ANY: # %bb.0: ; ANY-NEXT: retq - %r = fdiv float undef, %x + %r = fdiv fast float undef, %x ret float %r } define float @fdiv_undef_op1(float %x) { -; STRICT-LABEL: fdiv_undef_op1: -; STRICT: # %bb.0: -; STRICT-NEXT: divss %xmm0, %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fdiv_undef_op1: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq - %r = fdiv float %x, undef +; ANY-LABEL: fdiv_undef_op1: +; ANY: # %bb.0: +; ANY-NEXT: retq + %r = fdiv fast float %x, undef ret float %r } @@ -103,19 +73,15 @@ ; ANY-LABEL: frem_undef_op0: ; ANY: # %bb.0: ; ANY-NEXT: retq - %r = frem float undef, %x + %r = frem fast float undef, %x ret float %r } define float @frem_undef_op1(float %x) { -; STRICT-LABEL: frem_undef_op1: -; STRICT: # %bb.0: -; STRICT-NEXT: jmp fmodf # TAILCALL -; -; UNSAFE-LABEL: frem_undef_op1: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq - %r = frem float %x, undef +; ANY-LABEL: frem_undef_op1: +; ANY: # %bb.0: +; ANY-NEXT: retq + %r = frem fast float %x, undef ret float %r } @@ -135,14 +101,9 @@ } define float @fadd_undef_op1_fast(float %x) { -; STRICT-LABEL: fadd_undef_op1_fast: -; STRICT: # %bb.0: -; STRICT-NEXT: addss %xmm0, %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fadd_undef_op1_fast: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq +; ANY-LABEL: fadd_undef_op1_fast: +; ANY: # %bb.0: +; ANY-NEXT: retq %r = fadd fast float %x, undef ret float %r } @@ -182,14 +143,9 @@ } define float @fmul_undef_op1_fast(float %x) { -; STRICT-LABEL: fmul_undef_op1_fast: -; STRICT: # %bb.0: -; STRICT-NEXT: mulss %xmm0, %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fmul_undef_op1_fast: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq +; ANY-LABEL: fmul_undef_op1_fast: +; ANY: # %bb.0: +; ANY-NEXT: retq %r = fmul fast float %x, undef ret float %r } @@ -224,13 +180,9 @@ } define float @frem_undef_op1_fast(float %x) { -; STRICT-LABEL: frem_undef_op1_fast: -; STRICT: # %bb.0: -; STRICT-NEXT: jmp fmodf # TAILCALL -; -; UNSAFE-LABEL: frem_undef_op1_fast: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq +; ANY-LABEL: frem_undef_op1_fast: +; ANY: # %bb.0: +; ANY-NEXT: retq %r = frem fast float %x, undef ret float %r } @@ -238,15 +190,10 @@ ; Constant folding - undef undef. define double @fadd_undef_undef(double %x) { -; STRICT-LABEL: fadd_undef_undef: -; STRICT: # %bb.0: -; STRICT-NEXT: addsd %xmm0, %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fadd_undef_undef: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq - %r = fadd double undef, undef +; ANY-LABEL: fadd_undef_undef: +; ANY: # %bb.0: +; ANY-NEXT: retq + %r = fadd fast double undef, undef ret double %r } @@ -254,20 +201,15 @@ ; ANY-LABEL: fsub_undef_undef: ; ANY: # %bb.0: ; ANY-NEXT: retq - %r = fsub double undef, undef + %r = fsub fast double undef, undef ret double %r } define double @fmul_undef_undef(double %x) { -; STRICT-LABEL: fmul_undef_undef: -; STRICT: # %bb.0: -; STRICT-NEXT: mulsd %xmm0, %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fmul_undef_undef: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq - %r = fmul double undef, undef +; ANY-LABEL: fmul_undef_undef: +; ANY: # %bb.0: +; ANY-NEXT: retq + %r = fmul fast double undef, undef ret double %r } @@ -275,7 +217,7 @@ ; ANY-LABEL: fdiv_undef_undef: ; ANY: # %bb.0: ; ANY-NEXT: retq - %r = fdiv double undef, undef + %r = fdiv fast double undef, undef ret double %r } @@ -283,7 +225,7 @@ ; ANY-LABEL: frem_undef_undef: ; ANY: # %bb.0: ; ANY-NEXT: retq - %r = frem double undef, undef + %r = frem fast double undef, undef ret double %r } @@ -303,15 +245,10 @@ } define float @fadd_undef_op1_constant(float %x) { -; STRICT-LABEL: fadd_undef_op1_constant: -; STRICT: # %bb.0: -; STRICT-NEXT: addss {{.*}}(%rip), %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fadd_undef_op1_constant: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq - %r = fadd float 2.0, undef +; ANY-LABEL: fadd_undef_op1_constant: +; ANY: # %bb.0: +; ANY-NEXT: retq + %r = fadd fast float 2.0, undef ret float %r } @@ -324,16 +261,10 @@ } define float @fsub_undef_op1_constant(float %x) { -; STRICT-LABEL: fsub_undef_op1_constant: -; STRICT: # %bb.0: -; STRICT-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero -; STRICT-NEXT: subss %xmm0, %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fsub_undef_op1_constant: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq - %r = fsub float 4.0, undef +; ANY-LABEL: fsub_undef_op1_constant: +; ANY: # %bb.0: +; ANY-NEXT: retq + %r = fsub fast float 4.0, undef ret float %r } @@ -351,15 +282,10 @@ } define float @fmul_undef_op1_constant(float %x) { -; STRICT-LABEL: fmul_undef_op1_constant: -; STRICT: # %bb.0: -; STRICT-NEXT: mulss {{.*}}(%rip), %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fmul_undef_op1_constant: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq - %r = fmul float 6.0, undef +; ANY-LABEL: fmul_undef_op1_constant: +; ANY: # %bb.0: +; ANY-NEXT: retq + %r = fmul fast float 6.0, undef ret float %r } @@ -372,16 +298,10 @@ } define float @fdiv_undef_op1_constant(float %x) { -; STRICT-LABEL: fdiv_undef_op1_constant: -; STRICT: # %bb.0: -; STRICT-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero -; STRICT-NEXT: divss %xmm0, %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fdiv_undef_op1_constant: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq - %r = fdiv float 8.0, undef +; ANY-LABEL: fdiv_undef_op1_constant: +; ANY: # %bb.0: +; ANY-NEXT: retq + %r = fdiv fast float 8.0, undef ret float %r } @@ -394,42 +314,27 @@ } define float @frem_undef_op1_constant(float %x) { -; STRICT-LABEL: frem_undef_op1_constant: -; STRICT: # %bb.0: -; STRICT-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero -; STRICT-NEXT: jmp fmodf # TAILCALL -; -; UNSAFE-LABEL: frem_undef_op1_constant: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq - %r = frem float 10.0, undef +; ANY-LABEL: frem_undef_op1_constant: +; ANY: # %bb.0: +; ANY-NEXT: retq + %r = frem fast float 10.0, undef ret float %r } ; Constant folding - special constants: NaN. define double @fadd_undef_op0_constant_nan(double %x) { -; STRICT-LABEL: fadd_undef_op0_constant_nan: -; STRICT: # %bb.0: -; STRICT-NEXT: addsd {{.*}}(%rip), %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fadd_undef_op0_constant_nan: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq - %r = fadd double undef, 0x7FF8000000000000 +; ANY-LABEL: fadd_undef_op0_constant_nan: +; ANY: # %bb.0: +; ANY-NEXT: retq + %r = fadd fast double undef, 0x7FF8000000000000 ret double %r } define double @fadd_undef_op1_fast_constant_nan(double %x) { -; STRICT-LABEL: fadd_undef_op1_fast_constant_nan: -; STRICT: # %bb.0: -; STRICT-NEXT: addsd {{.*}}(%rip), %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fadd_undef_op1_fast_constant_nan: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq +; ANY-LABEL: fadd_undef_op1_fast_constant_nan: +; ANY: # %bb.0: +; ANY-NEXT: retq %r = fadd fast double 0xFFF0000000000001, undef ret double %r } @@ -457,27 +362,17 @@ } define double @fmul_undef_op0_constant_nan(double %x) { -; STRICT-LABEL: fmul_undef_op0_constant_nan: -; STRICT: # %bb.0: -; STRICT-NEXT: mulsd {{.*}}(%rip), %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fmul_undef_op0_constant_nan: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq - %r = fmul double undef, 0x7FF8000000000100 +; ANY-LABEL: fmul_undef_op0_constant_nan: +; ANY: # %bb.0: +; ANY-NEXT: retq + %r = fmul fast double undef, 0x7FF8000000000100 ret double %r } define double @fmul_undef_op1_fast_constant_nan(double %x) { -; STRICT-LABEL: fmul_undef_op1_fast_constant_nan: -; STRICT: # %bb.0: -; STRICT-NEXT: mulsd {{.*}}(%rip), %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fmul_undef_op1_fast_constant_nan: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq +; ANY-LABEL: fmul_undef_op1_fast_constant_nan: +; ANY: # %bb.0: +; ANY-NEXT: retq %r = fmul fast double 0xFFF0000000000101, undef ret double %r } @@ -508,19 +403,14 @@ ; ANY-LABEL: frem_undef_op0_constant_nan: ; ANY: # %bb.0: ; ANY-NEXT: retq - %r = frem double undef, 0x7FF8000000001000 + %r = frem fast double undef, 0x7FF8000000001000 ret double %r } define double @frem_undef_op1_fast_constant_nan(double %x) { -; STRICT-LABEL: frem_undef_op1_fast_constant_nan: -; STRICT: # %bb.0: -; STRICT-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero -; STRICT-NEXT: jmp fmod # TAILCALL -; -; UNSAFE-LABEL: frem_undef_op1_fast_constant_nan: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq +; ANY-LABEL: frem_undef_op1_fast_constant_nan: +; ANY: # %bb.0: +; ANY-NEXT: retq %r = frem fast double 0xFFF0000000001001, undef ret double %r } @@ -528,27 +418,17 @@ ; Constant folding - special constants: Inf. define double @fadd_undef_op0_constant_inf(double %x) { -; STRICT-LABEL: fadd_undef_op0_constant_inf: -; STRICT: # %bb.0: -; STRICT-NEXT: addsd {{.*}}(%rip), %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fadd_undef_op0_constant_inf: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq - %r = fadd double undef, 0x7FF0000000000000 +; ANY-LABEL: fadd_undef_op0_constant_inf: +; ANY: # %bb.0: +; ANY-NEXT: retq + %r = fadd fast double undef, 0x7FF0000000000000 ret double %r } define double @fadd_undef_op1_fast_constant_inf(double %x) { -; STRICT-LABEL: fadd_undef_op1_fast_constant_inf: -; STRICT: # %bb.0: -; STRICT-NEXT: addsd {{.*}}(%rip), %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fadd_undef_op1_fast_constant_inf: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq +; ANY-LABEL: fadd_undef_op1_fast_constant_inf: +; ANY: # %bb.0: +; ANY-NEXT: retq %r = fadd fast double 0xFFF0000000000000, undef ret double %r } @@ -557,7 +437,7 @@ ; ANY-LABEL: fsub_undef_op0_constant_inf: ; ANY: # %bb.0: ; ANY-NEXT: retq - %r = fsub double undef, 0xFFF0000000000000 + %r = fsub fast double undef, 0xFFF0000000000000 ret double %r } @@ -576,27 +456,17 @@ } define double @fmul_undef_op0_constant_inf(double %x) { -; STRICT-LABEL: fmul_undef_op0_constant_inf: -; STRICT: # %bb.0: -; STRICT-NEXT: mulsd {{.*}}(%rip), %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fmul_undef_op0_constant_inf: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq - %r = fmul double undef, 0x7FF0000000000000 +; ANY-LABEL: fmul_undef_op0_constant_inf: +; ANY: # %bb.0: +; ANY-NEXT: retq + %r = fmul fast double undef, 0x7FF0000000000000 ret double %r } define double @fmul_undef_op1_fast_constant_inf(double %x) { -; STRICT-LABEL: fmul_undef_op1_fast_constant_inf: -; STRICT: # %bb.0: -; STRICT-NEXT: mulsd {{.*}}(%rip), %xmm0 -; STRICT-NEXT: retq -; -; UNSAFE-LABEL: fmul_undef_op1_fast_constant_inf: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq +; ANY-LABEL: fmul_undef_op1_fast_constant_inf: +; ANY: # %bb.0: +; ANY-NEXT: retq %r = fmul fast double 0xFFF0000000000000, undef ret double %r } @@ -627,19 +497,14 @@ ; ANY-LABEL: frem_undef_op0_constant_inf: ; ANY: # %bb.0: ; ANY-NEXT: retq - %r = frem double undef, 0x7FF0000000000000 + %r = frem fast double undef, 0x7FF0000000000000 ret double %r } define double @frem_undef_op1_fast_constant_inf(double %x) { -; STRICT-LABEL: frem_undef_op1_fast_constant_inf: -; STRICT: # %bb.0: -; STRICT-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero -; STRICT-NEXT: jmp fmod # TAILCALL -; -; UNSAFE-LABEL: frem_undef_op1_fast_constant_inf: -; UNSAFE: # %bb.0: -; UNSAFE-NEXT: retq +; ANY-LABEL: frem_undef_op1_fast_constant_inf: +; ANY: # %bb.0: +; ANY-NEXT: retq %r = frem fast double 0xFFF0000000000000, undef ret double %r }