[llvm] [InstCombine] optimize powi(X,Y)/X with Ofast (PR #67236)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 25 05:23:55 PDT 2023


================
@@ -258,3 +259,23 @@ define double @different_types_powi(double %x, i32 %y, i64 %z) {
   %mul = fmul reassoc double %p2, %p1
   ret double %mul
 }
+
+define nofpclass(nan inf) double @fdiv_pow_powi(double %x) {
+; CHECK-LABEL: @fdiv_pow_powi(
+; CHECK-NEXT:    [[DIV:%.*]] = fmul fast double [[X:%.*]], [[X]]
+; CHECK-NEXT:    ret double [[DIV]]
+;
+  %p1 = call fast double @llvm.powi.f64.i32(double %x, i32 3)
+  %div = fdiv fast double %p1, %x
+  ret double %div
+}
+
+define nofpclass(nan inf) float @fdiv_powf_powi(float %x) {
+; CHECK-LABEL: @fdiv_powf_powi(
+; CHECK-NEXT:    [[DIV:%.*]] = call fast float @llvm.powi.f32.i32(float [[X:%.*]], i32 99)
+; CHECK-NEXT:    ret float [[DIV]]
+;
+  %p1 = call fast float @llvm.powi.f32.i32(float %x, i32 100)
+  %div = fdiv fast float %p1, %x
+  ret float %div
+}
----------------
vfdff wrote:

Add fdiv_pow_powi_multi_use for the suggested multi-use test, thanks

https://github.com/llvm/llvm-project/pull/67236


More information about the llvm-commits mailing list