[llvm] r359566 - [SelectionDAG] remove div-by-zero constant folding restriction

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 30 07:37:15 PDT 2019


Author: spatel
Date: Tue Apr 30 07:37:15 2019
New Revision: 359566

URL: http://llvm.org/viewvc/llvm-project?rev=359566&view=rev
Log:
[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.

Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
    llvm/trunk/test/CodeGen/AArch64/fp-const-fold.ll
    llvm/trunk/test/CodeGen/X86/fdiv-combine.ll

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=359566&r1=359565&r2=359566&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Tue Apr 30 07:37:15 2019
@@ -4816,17 +4816,13 @@ SDValue SelectionDAG::foldConstantFPMath
       break;
     case ISD::FDIV:
       Status = C1.divide(C2, APFloat::rmNearestTiesToEven);
-      if (!HasFPExceptions || (Status != APFloat::opInvalidOp &&
-                               Status != APFloat::opDivByZero)) {
+      if (!HasFPExceptions || Status != APFloat::opInvalidOp)
         return getConstantFP(C1, DL, VT);
-      }
       break;
     case ISD::FREM:
       Status = C1.mod(C2);
-      if (!HasFPExceptions || (Status != APFloat::opInvalidOp &&
-                               Status != APFloat::opDivByZero)) {
+      if (!HasFPExceptions || Status != APFloat::opInvalidOp)
         return getConstantFP(C1, DL, VT);
-      }
       break;
     case ISD::FCOPYSIGN:
       C1.copySign(C2);
@@ -4840,7 +4836,7 @@ SDValue SelectionDAG::foldConstantFPMath
     // This can return overflow, underflow, or inexact; we don't care.
     // FIXME need to be more flexible about rounding mode.
     (void) C1.convert(EVTToAPFloatSemantics(VT), APFloat::rmNearestTiesToEven,
-                     &Unused);
+                      &Unused);
     return getConstantFP(C1, DL, VT);
   }
 

Modified: llvm/trunk/test/CodeGen/AArch64/fp-const-fold.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/fp-const-fold.ll?rev=359566&r1=359565&r2=359566&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/fp-const-fold.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/fp-const-fold.ll Tue Apr 30 07:37:15 2019
@@ -6,10 +6,8 @@
 define double @constant_fold_fdiv_by_zero(double* %p) {
 ; CHECK-LABEL: constant_fold_fdiv_by_zero:
 ; CHECK:       // %bb.0:
-; CHECK-NEXT:    mov x8, #1
-; CHECK-NEXT:    fmov d0, xzr
-; CHECK-NEXT:    fmov d1, x8
-; CHECK-NEXT:    fdiv d0, d1, d0
+; CHECK-NEXT:    mov x8, #9218868437227405312
+; CHECK-NEXT:    fmov d0, x8
 ; CHECK-NEXT:    ret
   %r = fdiv double 4.940660e-324, 0.0
   ret double %r

Modified: llvm/trunk/test/CodeGen/X86/fdiv-combine.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/fdiv-combine.ll?rev=359566&r1=359565&r2=359566&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/fdiv-combine.ll (original)
+++ llvm/trunk/test/CodeGen/X86/fdiv-combine.ll Tue Apr 30 07:37:15 2019
@@ -115,16 +115,7 @@ define float @div_select_constant_fold(i
 define float @div_select_constant_fold_zero(i1 zeroext %arg) {
 ; CHECK-LABEL: div_select_constant_fold_zero:
 ; CHECK:       # %bb.0:
-; CHECK-NEXT:    testl %edi, %edi
-; CHECK-NEXT:    jne .LBB7_1
-; CHECK-NEXT:  # %bb.2:
 ; CHECK-NEXT:    movss {{.*#+}} xmm0 = mem[0],zero,zero,zero
-; CHECK-NEXT:    jmp .LBB7_3
-; CHECK-NEXT:  .LBB7_1:
-; CHECK-NEXT:    movss {{.*#+}} xmm0 = mem[0],zero,zero,zero
-; CHECK-NEXT:  .LBB7_3:
-; CHECK-NEXT:    xorps %xmm1, %xmm1
-; CHECK-NEXT:    divss %xmm1, %xmm0
 ; CHECK-NEXT:    retq
   %tmp = select i1 %arg, float 5.000000e+00, float 6.000000e+00
   %B2 = fdiv float %tmp, 0.000000e+00




More information about the llvm-commits mailing list