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

Andy Kaylor via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 12 11:14:00 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)
----------------
andykaylor wrote:

There was a discussion a few years ago about some place where we were checking reassoc when what we really wanted to do was distribution. I don't remember what the outcome was. As I said, I'd really like to have a broadly defined "algebraic-identity" flag, but we're out of bits (as currently implemented).

I think we agree that "-ffast-math" (and -funsafe-math-optimizations) should definitely allow transformations like this, but once you start turning off individual flags (which is important for users who are trying to locally restrict fast-math to solve accuracy problems), it's hard to say which combination should be required from the current set.

With the current "isFast()" check, even disabling contraction blocks the transformation, which is surely not what we want.

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


More information about the llvm-commits mailing list