[llvm] [AMDGPU] Fix canonicalization of truncated values. (PR #83054)

Harald van Dijk via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 5 02:27:33 PST 2024


================
@@ -26258,6 +26258,24 @@ SDValue DAGCombiner::visitFP_TO_FP16(SDNode *N) {
   if (N0->getOpcode() == ISD::FP16_TO_FP)
     return N0->getOperand(0);
 
+  // fold (fp_to_fp16 (freeze (fp16_to_fp (fp_to_fp16 op))))
----------------
hvdijk wrote:

Yes, exactly that. Aside from SNaN handling, `(fp_round (fp_extend x))` and `(fp_extend (fp_round x, /*trunc*/1))` are always equal to `x` and so for code that does not care about SNaNs, these are useful to optimise away. But `(fp_round (fcanonicalize (fp_extend x)))` and `(fp_extend (fcanonicalize (fp_round x, /*trunc*/1)))` must handle SNaNs, so we cannot just optimise the `fcanonicalize` to a no-op on the basis that `fp_extend`/`fp_round` will already have canonicalized.

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


More information about the llvm-commits mailing list