[llvm-branch-commits] [SPARC] Use op-then-neg instructions when we have VIS3 (PR #135717)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Apr 20 01:08:45 PDT 2025
================
@@ -316,4 +316,17 @@ def : Pat<(i64 (sext (i32 (bitconvert f32:$src)))), (MOVSTOSW $src)>;
def : Pat<(f32 (bitconvert i32:$src)), (MOVWTOS $src)>;
def : Pat<(i64 (bitconvert f64:$src)), (MOVDTOX $src)>;
def : Pat<(f64 (bitconvert i64:$src)), (MOVXTOD $src)>;
+
+// OP-then-neg FP operations.
+def : Pat<(f32 (fneg (fadd f32:$rs1, f32:$rs2))), (FNADDS $rs1, $rs2)>;
+def : Pat<(f64 (fneg (fadd f64:$rs1, f64:$rs2))), (FNADDD $rs1, $rs2)>;
+def : Pat<(f32 (fneg (fmul f32:$rs1, f32:$rs2))), (FNMULS $rs1, $rs2)>;
+def : Pat<(f32 (fmul (fneg f32:$rs1), f32:$rs2)), (FNMULS $rs1, $rs2)>;
+def : Pat<(f32 (fmul f32:$rs1, (fneg f32:$rs2))), (FNMULS $rs1, $rs2)>;
+def : Pat<(f64 (fneg (fmul f64:$rs1, f64:$rs2))), (FNMULD $rs1, $rs2)>;
+def : Pat<(f64 (fmul (fneg f64:$rs1), f64:$rs2)), (FNMULD $rs1, $rs2)>;
+def : Pat<(f64 (fmul f64:$rs1, (fneg f64:$rs2))), (FNMULD $rs1, $rs2)>;
+def : Pat<(f64 (fneg (fmul (fpextend f32:$rs1), (fpextend f32:$rs2)))), (FNSMULD $rs1, $rs2)>;
+def : Pat<(f64 (fmul (fneg (fpextend f32:$rs1)), (fpextend f32:$rs2))), (FNSMULD $rs1, $rs2)>;
+def : Pat<(f64 (fmul (fpextend f32:$rs1), (fneg (fpextend f32:$rs2)))), (FNSMULD $rs1, $rs2)>;
----------------
koachan wrote:
I don't think the backend tries to do anything fancy with FP, so probably it just passes expressions through `getNegatedExpression`.
That being said, on a quick reading of it:
- `-(a+b)` can be turned into `-a-b` or `-b-a`, but only if we don't care about signed zeros.
- `-(a*b)` will (?) be turned into `-a*b` or `a*-b`.
So I guess for multiplies I only need to handle the `-a*b` and `a*-b` variants, but for addition... is there a way to enable a pattern conditionally on `Options.NoSignedZerosFPMath || Flags.hasNoSignedZeros()`?
https://github.com/llvm/llvm-project/pull/135717
More information about the llvm-branch-commits
mailing list