[llvm] GlobalISel needs fdiv 1 / sqrt(x) to rsq combine (PR #78673)
Pierre van Houtryve via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 19 00:06:41 PST 2024
================
@@ -33,6 +33,11 @@ def rcp_sqrt_to_rsq : GICombineRule<
[{ return matchRcpSqrtToRsq(*${rcp}, ${matchinfo}); }]),
(apply [{ Helper.applyBuildFn(*${rcp}, ${matchinfo}); }])>;
+def fdiv_1_by_sqrt_to_rsq : GICombineRule<
+ (defs root:$root, build_fn_matchinfo:$matchinfo),
+ (match (wip_match_opcode G_FSQRT, G_FDIV):$root,
+ [{ return matchFDivSqrt(*${root}, ${matchinfo}); }]),
----------------
Pierre-vh wrote:
You can do this fully in MIR patterns :) https://llvm.org/docs/GlobalISel/MIRPatterns.html
We just can't match FP constants yet so that needs to be done in C++
I also don't know if we want this for half only or for all FP types. If it's the former, you'd also need to check that the type of `$dst` is `LLT::scalar(16)`.
```suggestion
(defs root:$dst),
(match (G_FSQRT $sqrt, $x),
(G_FCONSTANT $one, $fpimm),
(G_FDIV $dst, $sqrt, $fpimm, (MIFlags FmContract)),
[{ return ${fpimm}.getOperand(1).isExactlyValue(1.0); }]),
```
https://github.com/llvm/llvm-project/pull/78673
More information about the llvm-commits
mailing list