[PATCH] D59500: [ConstantFolding] Fix GetConstantFoldFPValue to avoid cast overflow.

Bixia Zheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 19 09:13:48 PDT 2019


bixia updated this revision to Diff 191328.
bixia added a comment.

Update commit message.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59500/new/

https://reviews.llvm.org/D59500

Files:
  lib/Analysis/ConstantFolding.cpp
  test/Transforms/ConstProp/calls.ll


Index: test/Transforms/ConstProp/calls.ll
===================================================================
--- test/Transforms/ConstProp/calls.ll
+++ test/Transforms/ConstProp/calls.ll
@@ -193,4 +193,14 @@
   ret double %0
 }
 
+define float @test_intrinsic_pow_f32_overflow() nounwind uwtable ssp {
+entry:
+; CHECK-LABEL: @test_intrinsic_pow(
+; CHECK-NOT: call
+; CHECK: ret
+  %0 = call float @llvm.pow.f32(float 40.0, float 50.0)
+  ret float %0
+}
+
 declare double @llvm.pow.f64(double, double) nounwind readonly
+declare float @llvm.pow.f32(float, float) nounwind readonly
Index: lib/Analysis/ConstantFolding.cpp
===================================================================
--- lib/Analysis/ConstantFolding.cpp
+++ lib/Analysis/ConstantFolding.cpp
@@ -1517,14 +1517,12 @@
 namespace {
 
 Constant *GetConstantFoldFPValue(double V, Type *Ty) {
-  if (Ty->isHalfTy()) {
+  if (Ty->isHalfTy() || Ty->isFloatTy()) {
     APFloat APF(V);
     bool unused;
-    APF.convert(APFloat::IEEEhalf(), APFloat::rmNearestTiesToEven, &unused);
+    APF.convert(Ty->getFltSemantics(), APFloat::rmNearestTiesToEven, &unused);
     return ConstantFP::get(Ty->getContext(), APF);
   }
-  if (Ty->isFloatTy())
-    return ConstantFP::get(Ty->getContext(), APFloat((float)V));
   if (Ty->isDoubleTy())
     return ConstantFP::get(Ty->getContext(), APFloat(V));
   llvm_unreachable("Can only constant fold half/float/double");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59500.191328.patch
Type: text/x-patch
Size: 1423 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190319/1bc1671f/attachment.bin>


More information about the llvm-commits mailing list