summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp3
-rw-r--r--llvm/test/Transforms/InstSimplify/call.ll8
2 files changed, 5 insertions, 6 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 7942cb09e84..d151b78f04c 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5090,6 +5090,9 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
// copysign X, X --> X
if (Op0 == Op1)
return Op0;
+ // copysign -X, X --> X
+ if (match(Op0, m_FNeg(m_Specific(Op1))))
+ return Op1;
break;
case Intrinsic::maxnum:
case Intrinsic::minnum:
diff --git a/llvm/test/Transforms/InstSimplify/call.ll b/llvm/test/Transforms/InstSimplify/call.ll
index 4a0dc41accc..a8a9bf54378 100644
--- a/llvm/test/Transforms/InstSimplify/call.ll
+++ b/llvm/test/Transforms/InstSimplify/call.ll
@@ -964,9 +964,7 @@ define <2 x double> @negated_sign_arg_vec(<2 x double> %x) {
define float @negated_mag_arg(float %x) {
; CHECK-LABEL: @negated_mag_arg(
-; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan float [[X:%.*]]
-; CHECK-NEXT: [[R:%.*]] = call ninf float @llvm.copysign.f32(float [[NEGX]], float [[X]])
-; CHECK-NEXT: ret float [[R]]
+; CHECK-NEXT: ret float [[X:%.*]]
;
%negx = fneg nnan float %x
%r = call ninf float @llvm.copysign.f32(float %negx, float %x)
@@ -975,9 +973,7 @@ define float @negated_mag_arg(float %x) {
define <2 x double> @negated_mag_arg_vec(<2 x double> %x) {
; CHECK-LABEL: @negated_mag_arg_vec(
-; CHECK-NEXT: [[NEGX:%.*]] = fneg afn <2 x double> [[X:%.*]]
-; CHECK-NEXT: [[R:%.*]] = call arcp <2 x double> @llvm.copysign.v2f64(<2 x double> [[NEGX]], <2 x double> [[X]])
-; CHECK-NEXT: ret <2 x double> [[R]]
+; CHECK-NEXT: ret <2 x double> [[X:%.*]]
;
%negx = fneg afn <2 x double> %x
%r = call arcp <2 x double> @llvm.copysign.v2f64(<2 x double> %negx, <2 x double> %x)
OpenPOWER on IntegriCloud