From: Kewen Lin Date: Wed, 10 Jan 2024 05:06:12 +0000 (-0600) Subject: rs6000: Make copysign (x, -1) back to -abs (x) for IEEE128 float [PR112606] X-Git-Tag: basepoints/gcc-15~3049 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf5f6a048e376ab0d2f7bc283c158605e1166061;p=thirdparty%2Fgcc.git rs6000: Make copysign (x, -1) back to -abs (x) for IEEE128 float [PR112606] I noticed that commit r14-6192 can't help PR112606 #c3 as it only takes care of SF/DF but TF/KF can still suffer the issue. Similar to commit r14-6192, this patch is to take care of copysign3 with IEEE128 as well. PR target/112606 gcc/ChangeLog: * config/rs6000/rs6000.md (copysign3 IEEE128): Change predicate of the last argument from altivec_register_operand to any_operand. If operands[2] is CONST_DOUBLE, emit abs or neg abs depending on its sign otherwise if it doesn't satisfy altivec_register_operand, force it to REG using copy_to_mode_reg. --- diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md index c880cec33a2a..bc8bc6ab060b 100644 --- a/gcc/config/rs6000/rs6000.md +++ b/gcc/config/rs6000/rs6000.md @@ -15020,9 +15020,27 @@ (define_expand "copysign3" [(use (match_operand:IEEE128 0 "altivec_register_operand")) (use (match_operand:IEEE128 1 "altivec_register_operand")) - (use (match_operand:IEEE128 2 "altivec_register_operand"))] + (use (match_operand:IEEE128 2 "any_operand"))] "FLOAT128_IEEE_P (mode)" { + /* Middle-end canonicalizes -fabs (x) to copysign (x, -1), + but PowerPC prefers -fabs (x). */ + if (CONST_DOUBLE_AS_FLOAT_P (operands[2])) + { + if (real_isneg (CONST_DOUBLE_REAL_VALUE (operands[2]))) + { + rtx abs_res = gen_reg_rtx (mode); + emit_insn (gen_abs2 (abs_res, operands[1])); + emit_insn (gen_neg2 (operands[0], abs_res)); + } + else + emit_insn (gen_abs2 (operands[0], operands[1])); + DONE; + } + + if (!altivec_register_operand (operands[2], mode)) + operands[2] = copy_to_mode_reg (mode, operands[2]); + if (TARGET_FLOAT128_HW) emit_insn (gen_copysign3_hard (operands[0], operands[1], operands[2]));