[loongarch][DAG][FREEZE] Fix crash when FREEZE a half(f16) type on loongarch by yxd-ym · Pull Request #107791 · llvm/llvm-project (original) (raw)

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

yxd-ym

@yxd-ym

@yxd-ym

@github-actions GitHub Actions

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot

@llvm/pr-subscribers-llvm-selectiondag

@llvm/pr-subscribers-backend-loongarch

Author: YANG Xudong (yxd-ym)

Changes

For zig with LLVM 19.1.0rc4, we are seeing the following error when bootstrapping a loongarch64-linux-musl target.

ziglang/zig-bootstrap#164 (comment)

It seems that this issue is caused by PromoteFloatResult is not handling FREEZE OP on loongarch.

Here is the reproduction of the error: https://godbolt.org/z/PPfvWjjG5

This patch adds the FREEZE OP handling with PromoteFloatRes_UnaryOp and adds a test case.

See: loongarch's handling of half:

Also see: other float promotion FREEZE handling


Full diff: https://github.com/llvm/llvm-project/pull/107791.diff

2 Files Affected:

diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp index b5c80005a0ecc1..51357dad5b30ec 100644 --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp @@ -2655,6 +2655,7 @@ void DAGTypeLegalizer::PromoteFloatResult(SDNode *N, unsigned ResNo) { case ISD::FLOG10: case ISD::FNEARBYINT: case ISD::FNEG:

@wangleiat

Thanks.
Perhaps we should override this interface.

bool softPromoteHalfType() const override { return true; }

We currently do not have any parameter passing specifications for f16 types,this may also cause the generated code to not meet expectations.

arsenm

@yxd-ym

Thanks. Perhaps we should override this interface.

bool softPromoteHalfType() const override { return true; }

We currently do not have any parameter passing specifications for f16 types,this may also cause the generated code to not meet expectations.

@wangleiat Changed the fix according to your suggestion and updated the tests. Would you please check it?

@yxd-ym

wangleiat

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yxd-ym

@heiher

cc @heiher @SixWeining

Also, is it possible to add this fix to release 19? Thanks!

Yes, this patch is also applicable to release 19.x. Thanks.

arsenm

@yxd-ym

arsenm

@SixWeining

Should the commit message be updated?

@yxd-ym

Should the commit message be updated?

Updated.

@github-actions GitHub Actions

@yxd-ym Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@yxd-ym yxd-ym deleted the fix-loongarch-freeze-f16 branch

September 13, 2024 09:32

@yxd-ym

@llvmbot

/cherry-pick 13280d9

Error: Command failed due to missing milestone.

@nikic

@nikic

Does this also fix #97975 on loongarch?

llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request

Sep 18, 2024

@yxd-ym @llvmbot

…ongarch (llvm#107791)

For zig with LLVM 19.1.0rc4, we are seeing the following error when bootstrapping a loongarch64-linux-musl target.

ziglang/zig-bootstrap#164 (comment)

It seems that this issue is caused by PromoteFloatResult is not handling FREEZE OP on loongarch.

Here is the reproduction of the error: https://godbolt.org/z/PPfvWjjG5

This patch adds the FREEZE OP handling with PromoteFloatRes_UnaryOp and adds a test case.

This patch changes loongarch's way of floating point promotion to soft promotion to avoid this problem.

See: loongarch's handling of half:

Also see: other float promotion FREEZE handling

llvm@0019c2f

(cherry picked from commit 13280d9)

@llvmbot

andrewrk added a commit to ziglang/zig-bootstrap that referenced this pull request

Sep 18, 2024

@andrewrk

@heiher

Does this also fix #97975 on loongarch?

Yes. it also fix #97981

This was referenced

Sep 20, 2024

@nikic nikic mentioned this pull request

Sep 20, 2024

heiher pushed a commit to llvmbot/llvm-project that referenced this pull request

Oct 19, 2024

@yxd-ym @heiher

…ongarch (llvm#107791)

For zig with LLVM 19.1.0rc4, we are seeing the following error when bootstrapping a loongarch64-linux-musl target.

ziglang/zig-bootstrap#164 (comment)

It seems that this issue is caused by PromoteFloatResult is not handling FREEZE OP on loongarch.

Here is the reproduction of the error: https://godbolt.org/z/PPfvWjjG5

This patch adds the FREEZE OP handling with PromoteFloatRes_UnaryOp and adds a test case.

This patch changes loongarch's way of floating point promotion to soft promotion to avoid this problem.

See: loongarch's handling of half:

Also see: other float promotion FREEZE handling

llvm@0019c2f

(cherry picked from commit 13280d9)

@Felipe940402

This was referenced

Nov 18, 2024

andrewrk added a commit to ziglang/zig-bootstrap that referenced this pull request

Jan 20, 2025

@andrewrk