llvm.org GIT mirror llvm / b413eef
[SelectionDAG] remove div-by-zero constant folding restriction We don't have this restriction in IR, so it should not be here either simply out of consistency. Code that wants to handle FP exceptions is expected to use the 'strict' variants of these nodes. We don't get the frem case because frem by 0.0 produces NaN (invalid), and that's the remaining check here (so the removed check for frem was dead code AFAIK). This is the only place in SDAG that uses "HasFPExceptions", so I think we should remove that entirely as a follow-up patch. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359566 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 1 year, 4 months ago
3 changed file(s) with 5 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
48154815 break;
48164816 case ISD::FDIV:
48174817 Status = C1.divide(C2, APFloat::rmNearestTiesToEven);
4818 if (!HasFPExceptions || (Status != APFloat::opInvalidOp &&
4819 Status != APFloat::opDivByZero)) {
4818 if (!HasFPExceptions || Status != APFloat::opInvalidOp)
48204819 return getConstantFP(C1, DL, VT);
4821 }
48224820 break;
48234821 case ISD::FREM:
48244822 Status = C1.mod(C2);
4825 if (!HasFPExceptions || (Status != APFloat::opInvalidOp &&
4826 Status != APFloat::opDivByZero)) {
4823 if (!HasFPExceptions || Status != APFloat::opInvalidOp)
48274824 return getConstantFP(C1, DL, VT);
4828 }
48294825 break;
48304826 case ISD::FCOPYSIGN:
48314827 C1.copySign(C2);
48394835 // This can return overflow, underflow, or inexact; we don't care.
48404836 // FIXME need to be more flexible about rounding mode.
48414837 (void) C1.convert(EVTToAPFloatSemantics(VT), APFloat::rmNearestTiesToEven,
4842 &Unused);
4838 &Unused);
48434839 return getConstantFP(C1, DL, VT);
48444840 }
48454841
55 define double @constant_fold_fdiv_by_zero(double* %p) {
66 ; CHECK-LABEL: constant_fold_fdiv_by_zero:
77 ; CHECK: // %bb.0:
8 ; CHECK-NEXT: mov x8, #1
9 ; CHECK-NEXT: fmov d0, xzr
10 ; CHECK-NEXT: fmov d1, x8
11 ; CHECK-NEXT: fdiv d0, d1, d0
8 ; CHECK-NEXT: mov x8, #9218868437227405312
9 ; CHECK-NEXT: fmov d0, x8
1210 ; CHECK-NEXT: ret
1311 %r = fdiv double 4.940660e-324, 0.0
1412 ret double %r
114114 define float @div_select_constant_fold_zero(i1 zeroext %arg) {
115115 ; CHECK-LABEL: div_select_constant_fold_zero:
116116 ; CHECK: # %bb.0:
117 ; CHECK-NEXT: testl %edi, %edi
118 ; CHECK-NEXT: jne .LBB7_1
119 ; CHECK-NEXT: # %bb.2:
120117 ; CHECK-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero
121 ; CHECK-NEXT: jmp .LBB7_3
122 ; CHECK-NEXT: .LBB7_1:
123 ; CHECK-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero
124 ; CHECK-NEXT: .LBB7_3:
125 ; CHECK-NEXT: xorps %xmm1, %xmm1
126 ; CHECK-NEXT: divss %xmm1, %xmm0
127118 ; CHECK-NEXT: retq
128119 %tmp = select i1 %arg, float 5.000000e+00, float 6.000000e+00
129120 %B2 = fdiv float %tmp, 0.000000e+00