[PATCH] Allow Const fold of llvm intrinsic ceil function
Karthik Bhat
kv.bhat at samsung.com
Tue Mar 11 00:44:58 PDT 2014
Hi hfinkel,
Hi Hal,
Added a patch to allow constfold of llvm intrinsic ceil function.
We should be able to const fold a call to ceil in a similar way as we are handling a call to floor.
Please let me know if this patch is ok to commit.
Thanks
Karthik Bhat
http://llvm-reviews.chandlerc.com/D3037
Files:
lib/Analysis/ConstantFolding.cpp
test/Transforms/InstCombine/ceil.ll
Index: lib/Analysis/ConstantFolding.cpp
===================================================================
--- lib/Analysis/ConstantFolding.cpp
+++ lib/Analysis/ConstantFolding.cpp
@@ -1186,6 +1186,7 @@
case Intrinsic::exp:
case Intrinsic::exp2:
case Intrinsic::floor:
+ case Intrinsic::ceil:
case Intrinsic::sqrt:
case Intrinsic::pow:
case Intrinsic::powi:
@@ -1390,6 +1391,8 @@
#endif
case Intrinsic::floor:
return ConstantFoldFP(floor, V, Ty);
+ case Intrinsic::ceil:
+ return ConstantFoldFP(ceil, V, Ty);
}
if (!TLI)
Index: test/Transforms/InstCombine/ceil.ll
===================================================================
--- test/Transforms/InstCombine/ceil.ll
+++ test/Transforms/InstCombine/ceil.ll
@@ -0,0 +1,49 @@
+; RUN: opt -S -instcombine < %s | FileCheck %s
+
+declare float @llvm.ceil.f32(float) #0
+declare double @llvm.ceil.f64(double) #0
+
+; CHECK-LABEL: @constant_fold_ceil_f32_01
+; CHECK-NEXT: ret float 1.000000e+00
+define float @constant_fold_ceil_f32_01() #0 {
+ %x = call float @llvm.ceil.f32(float 1.00) #0
+ ret float %x
+}
+
+; CHECK-LABEL: @constant_fold_ceil_f32_02
+; CHECK-NEXT: ret float 2.000000e+00
+define float @constant_fold_ceil_f32_02() #0 {
+ %x = call float @llvm.ceil.f32(float 1.25) #0
+ ret float %x
+}
+
+; CHECK-LABEL: @constant_fold_ceil_f32_03
+; CHECK-NEXT: ret float -1.000000e+00
+define float @constant_fold_ceil_f32_03() #0 {
+ %x = call float @llvm.ceil.f32(float -1.25) #0
+ ret float %x
+}
+
+; CHECK-LABEL: @constant_fold_ceil_f64_01
+; CHECK-NEXT: ret double 1.000000e+00
+define double @constant_fold_ceil_f64_01() #0 {
+ %x = call double @llvm.ceil.f64(double 1.0) #0
+ ret double %x
+}
+
+; CHECK-LABEL: @constant_fold_ceil_f64_02
+; CHECK-NEXT: ret double 2.000000e+00
+define double @constant_fold_ceil_f64_02() #0 {
+ %x = call double @llvm.ceil.f64(double 1.3) #0
+ ret double %x
+}
+
+; CHECK-LABEL: @constant_fold_ceil_f64_03
+; CHECK-NEXT: ret double -1.000000e+00
+define double @constant_fold_ceil_f64_03() #0 {
+ %x = call double @llvm.ceil.f64(double -1.75) #0
+ ret double %x
+}
+
+attributes #0 = { nounwind readnone }
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3037.1.patch
Type: text/x-patch
Size: 2188 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140311/e7bc3b58/attachment.bin>
More information about the llvm-commits
mailing list