This is an archive of the discontinued LLVM Phabricator instance.

[X86] Don't pass a 1 to the secon argument of ISD::FP_ROUND in LowerFCOPYSIGN.
ClosedPublic

Authored by craig.topper on Feb 4 2021, 7:29 PM.

Details

Summary

I don't think we have any reason to believe the FP_ROUND here doesn't change the value.

Found while trying to see if we still need the fp128 block in CanCombineFCOPYSIGN_EXTEND_ROUND.
Removing that check caused this FP_ROUND to fire for fp128 which introduced a libcall expansion that asserted for this being a 1.

Diff Detail

Event Timeline

craig.topper created this revision.Feb 4 2021, 7:29 PM
craig.topper requested review of this revision.Feb 4 2021, 7:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 4 2021, 7:29 PM
craig.topper retitled this revision from [X86] Don't 1 to FP_ROUND in LowerFCOPYSIGN. to [X86] Don't pass a 1 to the secon argument of ISD::FP_ROUND in LowerFCOPYSIGN..Feb 4 2021, 7:30 PM

I don't think we have any reason to believe the FP_ROUND here doesn't change the value.

But I think the change here doesn't matter since we clear all non sign bits later.

llvm/lib/Target/X86/X86ISelLowering.cpp
21903–21904

Better change the format as Lint suggested.

clang-format

pengfei accepted this revision.Feb 4 2021, 11:32 PM

LGTM. But if there's benefit for optimization if we use 1 here?

This revision is now accepted and ready to land.Feb 4 2021, 11:32 PM

LGTM. But if there's benefit for optimization if we use 1 here?

We're reconstructing an FP_ROUND that was removed by DAGCombine:visitFCOPYSIGN. DAGCombine didn't check the second operand before doing the combine. So we have to do the conservative thing when reconstructing it. I'm not sure how to retain the information unless we also add the operand to FCOPYSIGN.

LGTM. But if there's benefit for optimization if we use 1 here?

We're reconstructing an FP_ROUND that was removed by DAGCombine:visitFCOPYSIGN. DAGCombine didn't check the second operand before doing the combine. So we have to do the conservative thing when reconstructing it. I'm not sure how to retain the information unless we also add the operand to FCOPYSIGN.

Then why we need to do these FP_ROUND/FP_EXTEND things. I didn't find any cases in LangRef and tests that the type of Sign is different from Mag or result.

LGTM. But if there's benefit for optimization if we use 1 here?

We're reconstructing an FP_ROUND that was removed by DAGCombine:visitFCOPYSIGN. DAGCombine didn't check the second operand before doing the combine. So we have to do the conservative thing when reconstructing it. I'm not sure how to retain the information unless we also add the operand to FCOPYSIGN.

Then why we need to do these FP_ROUND/FP_EXTEND things. I didn't find any cases in LangRef and tests that the type of Sign is different from Mag or result.

The types are only allowed to be different in SelectionDAG not in IR.

LGTM. But if there's benefit for optimization if we use 1 here?

We're reconstructing an FP_ROUND that was removed by DAGCombine:visitFCOPYSIGN. DAGCombine didn't check the second operand before doing the combine. So we have to do the conservative thing when reconstructing it. I'm not sure how to retain the information unless we also add the operand to FCOPYSIGN.

Then why we need to do these FP_ROUND/FP_EXTEND things. I didn't find any cases in LangRef and tests that the type of Sign is different from Mag or result.

It’s specific to SelectionDAG. Not sure the complete history of why it exists. It causes some other issues. You can trace back through other reviews from https://reviews.llvm.org/D96037

RKSimon accepted this revision.Feb 5 2021, 9:58 AM

LGTM but I'd be happier if you can add a test case

LGTM but I'd be happier if you can add a test case

The use of that flag that I know of is to combine (fpext (fpround X, 1)) -> X if the type doesn't change. Since the FP_ROUND is being consumed by an expanded FCOPYSIGN after this, there won't be a fpext consuming it. Can you think of any other places it is used?

LGTM but I'd be happier if you can add a test case

The use of that flag that I know of is to combine (fpext (fpround X, 1)) -> X if the type doesn't change. Since the FP_ROUND is being consumed by an expanded FCOPYSIGN after this, there won't be a fpext consuming it. Can you think of any other places it is used?

No sorry @spatel do you know ?

I'm OK for the patch to go without a test tbh.

This revision was landed with ongoing or failed builds.Feb 6 2021, 10:48 AM
This revision was automatically updated to reflect the committed changes.
spatel added a comment.Feb 7 2021, 5:23 AM

LGTM but I'd be happier if you can add a test case

The use of that flag that I know of is to combine (fpext (fpround X, 1)) -> X if the type doesn't change. Since the FP_ROUND is being consumed by an expanded FCOPYSIGN after this, there won't be a fpext consuming it. Can you think of any other places it is used?

No sorry @spatel do you know ?

No, I don't know the history either.
I don't see any other uses of that extra param, so it might be possible to drop it completely? A potential complication is that we don't have fast-math-flags on all FP casts, so there may be some FP narrowing optimizations that are missed.