[llvm] [InstCombine] Add log-pow simplification for FP exponent edge case. (PR #76641)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 4 01:33:21 PST 2024


================
@@ -12,6 +12,28 @@ define double @log_pow(double %x, double %y) {
   ret double %log
 }
 
+define double @log_powi_const(double %x) {
+; CHECK-LABEL: @log_powi_const(
+; CHECK-NEXT:    [[LOG1:%.*]] = call fast double @llvm.log.f64(double [[X:%.*]])
+; CHECK-NEXT:    [[MUL:%.*]] = fmul fast double [[LOG1]], -3.000000e+00
+; CHECK-NEXT:    ret double [[MUL]]
+;
+  %pow = call fast double @llvm.powi.f64.i32(double %x, i32 -3)
+  %log = call fast double @log(double %pow)
+  ret double %log
+}
+
+define double @log_powi_nonconst(double %x, i32 %y) {
+; CHECK-LABEL: @log_powi_nonconst(
+; CHECK-NEXT:    [[LOG1:%.*]] = call fast double @llvm.log.f64(double [[X:%.*]])
+; CHECK-NEXT:    [[CAST:%.*]] = sitofp i32 [[Y:%.*]] to double
+; CHECK-NEXT:    [[MUL:%.*]] = fmul fast double [[LOG1]], [[CAST]]
+; CHECK-NEXT:    ret double [[MUL]]
+  %pow = call fast double @llvm.powi.f64.i32(double %x, i32 %y)
+  %log = call fast double @log(double %pow)
+  ret double %log
+}
+
----------------
arsenm wrote:

Can you also test with the f32 case, and some cases with missing flags?

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


More information about the llvm-commits mailing list