Skip to content

Commit c532d57

Browse files
committed
[InstCombine] Fix FMF propagation in copysign Mag, (copysign ?, X) -> copysign Mag, X
1 parent 4cd2b4a commit c532d57

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2673,8 +2673,10 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
26732673
// Propagate sign argument through nested calls:
26742674
// copysign Mag, (copysign ?, X) --> copysign Mag, X
26752675
Value *X;
2676-
if (match(Sign, m_Intrinsic<Intrinsic::copysign>(m_Value(), m_Value(X))))
2676+
if (match(Sign, m_Intrinsic<Intrinsic::copysign>(m_Value(), m_Value(X)))) {
2677+
II->andIRFlags(Sign);
26772678
return replaceOperand(*II, 1, X);
2679+
}
26782680

26792681
// Clear sign-bit of constant magnitude:
26802682
// copysign -MagC, X --> copysign MagC, X

llvm/test/Transforms/InstCombine/copysign.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ define float @not_known_positive_sign_arg(float %x, float %y) {
8282

8383
define float @copysign_sign_arg(float %x, float %y, float %z) {
8484
; CHECK-LABEL: @copysign_sign_arg(
85-
; CHECK-NEXT: [[R:%.*]] = call ninf float @llvm.copysign.f32(float [[X:%.*]], float [[Z:%.*]])
85+
; CHECK-NEXT: [[R:%.*]] = call float @llvm.copysign.f32(float [[X:%.*]], float [[Z:%.*]])
8686
; CHECK-NEXT: ret float [[R]]
8787
;
8888
%s = call reassoc float @llvm.copysign.f32(float %y, float %z)

0 commit comments

Comments
 (0)