Skip to content

Commit

Permalink
[InstSimplify] fold copysign with negated operand
Browse files Browse the repository at this point in the history
This is another transform suggested in PR44153:
https://bugs.llvm.org/show_bug.cgi?id=44153

The backend for some targets already manages to get
this if it converts copysign to bitwise logic.
  • Loading branch information
rotateright committed Dec 8, 2019
1 parent b324902 commit 12f39e0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
3 changes: 3 additions & 0 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 2 additions & 6 deletions llvm/test/Transforms/InstSimplify/call.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 12f39e0

Please sign in to comment.