Skip to content

Commit 1c4dd3a

Browse files
committed
[InstSimplify] fold copysign with negated operand, part 2
This is another transform suggested in PR44153: https://bugs.llvm.org/show_bug.cgi?id=44153 Unlike rG12f39e0fede9, it doesn't look like the backend matches this variant.
1 parent a05d7c2 commit 1c4dd3a

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5091,7 +5091,9 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
50915091
if (Op0 == Op1)
50925092
return Op0;
50935093
// copysign -X, X --> X
5094-
if (match(Op0, m_FNeg(m_Specific(Op1))))
5094+
// copysign X, -X --> -X
5095+
if (match(Op0, m_FNeg(m_Specific(Op1))) ||
5096+
match(Op1, m_FNeg(m_Specific(Op0))))
50955097
return Op1;
50965098
break;
50975099
case Intrinsic::maxnum:

llvm/test/Transforms/InstSimplify/call.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -943,8 +943,7 @@ define <2 x double> @copysign_same_operand_vec(<2 x double> %x) {
943943
define float @negated_sign_arg(float %x) {
944944
; CHECK-LABEL: @negated_sign_arg(
945945
; CHECK-NEXT: [[NEGX:%.*]] = fsub ninf float -0.000000e+00, [[X:%.*]]
946-
; CHECK-NEXT: [[R:%.*]] = call arcp float @llvm.copysign.f32(float [[X]], float [[NEGX]])
947-
; CHECK-NEXT: ret float [[R]]
946+
; CHECK-NEXT: ret float [[NEGX]]
948947
;
949948
%negx = fsub ninf float -0.0, %x
950949
%r = call arcp float @llvm.copysign.f32(float %x, float %negx)
@@ -954,8 +953,7 @@ define float @negated_sign_arg(float %x) {
954953
define <2 x double> @negated_sign_arg_vec(<2 x double> %x) {
955954
; CHECK-LABEL: @negated_sign_arg_vec(
956955
; CHECK-NEXT: [[NEGX:%.*]] = fneg afn <2 x double> [[X:%.*]]
957-
; CHECK-NEXT: [[R:%.*]] = call arcp <2 x double> @llvm.copysign.v2f64(<2 x double> [[X]], <2 x double> [[NEGX]])
958-
; CHECK-NEXT: ret <2 x double> [[R]]
956+
; CHECK-NEXT: ret <2 x double> [[NEGX]]
959957
;
960958
%negx = fneg afn <2 x double> %x
961959
%r = call arcp <2 x double> @llvm.copysign.v2f64(<2 x double> %x, <2 x double> %negx)

0 commit comments

Comments
 (0)