[llvm] [InstCombine] optimize powi(X,Y) * X with Ofast (PR #69998)

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 24 04:37:52 PDT 2023


vfdff wrote:

> We have three variants of this optimization now: `powi(x,a)*powi(x,b) => powi(x,a+b)`, `powi(x,a)/x => powi(x,a-1)` and `powi(x,a)*x => powi(x,a+1)`.
> 
> I'd suggest to move most of the transform into a helper function, that will accept `x, a, b`, `x, a, -1` and `x, a, 1` in the above cases and then do the common checks and transform.
> 
> This will also fix the bug in the current `powi * powi` transform, which fails to perform the necessary overflow check.

Three variants of this optimization have many differences except the pattern match form,  and it seems the only common check is `hasAllowReassoc()` for instruction `I`?
1、`powi(X, Y) / X --> powi(X, Y-1)` need  `hasAllowReassoc()` and `hasNoNaNs()` for both` I and powi(X, Y)` , called in visitFDiv, check 
2、`powi(X, Y) * X --> powi(X, Y+1)` need `hasAllowReassoc()`  for both `I and powi(X, Y)` , called in visitFMul
3、`powi(x, y) * powi(x, z) -> powi(x, y + z)` need `hasAllowReassoc()` for all `I、powi(X, Y) and powi(X, Z)` , called in visitFMul



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


More information about the llvm-commits mailing list