fold fp div by 0 to inf, the way gcc does. This is legal according to the FP spec
authorAndrew Lenharth <andrewl@lenharth.org>
Mon, 2 May 2005 21:25:47 +0000 (21:25 +0000)
committerAndrew Lenharth <andrewl@lenharth.org>
Mon, 2 May 2005 21:25:47 +0000 (21:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21655 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/ConstantFold.cpp

index 98fcf1a32e43c005d8f8c4aef82ff424a2fdaaf8..8cb1c0745347e2feb2816a95e001d6aa8b259801 100644 (file)
@@ -470,6 +470,13 @@ struct DirectFPRules
                                    (BuiltinType)V2->getValue());
     return ConstantClass::get(*Ty, Result);
   }
+  static Constant *Div(const ConstantClass *V1, const ConstantClass *V2) {
+    if (V2->isExactlyValue(0.0)) return ConstantClass::get(*Ty, INFINITY);
+    if (V2->isExactlyValue(-0.0)) return ConstantClass::get(*Ty, -INFINITY);
+    if (V2->isNullValue()) return 0;
+    BuiltinType R = (BuiltinType)V1->getValue() / (BuiltinType)V2->getValue();
+    return ConstantClass::get(*Ty, R);
+  }
 };