Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[loongarch][DAG][FREEZE] Fix crash when FREEZE a half(f16) type on loongarch #107791

Merged
merged 10 commits into from
Sep 13, 2024

Conversation

yxd-ym
Copy link
Contributor

@yxd-ym yxd-ym commented Sep 9, 2024

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

Copy link

github-actions bot commented Sep 9, 2024

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
Copy link
Collaborator

llvmbot commented Sep 9, 2024

@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:

  • (modified) llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp (+1)
  • (modified) llvm/test/CodeGen/LoongArch/fp16-promote.ll (+15)
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:
+    case ISD::FREEZE:
     case ISD::FRINT:
     case ISD::FROUND:
     case ISD::FROUNDEVEN:
diff --git a/llvm/test/CodeGen/LoongArch/fp16-promote.ll b/llvm/test/CodeGen/LoongArch/fp16-promote.ll
index 75f920b43a06ce..a139428f2d61e9 100644
--- a/llvm/test/CodeGen/LoongArch/fp16-promote.ll
+++ b/llvm/test/CodeGen/LoongArch/fp16-promote.ll
@@ -324,3 +324,18 @@ define void @test_fmul_mem(ptr %p, ptr %q) nounwind {
   store half %r, ptr %p
   ret void
 }
+
+define half @freeze_half() nounwind {
+; LA32-LABEL: freeze_half:
+; LA32:       # %bb.0:
+; LA32-NEXT:    fadd.s	$fa0, $fa0, $fa0
+; LA32-NEXT:    ret
+;
+; LA64-LABEL: freeze_half:
+; LA64:       # %bb.0:
+; LA64-NEXT:    fadd.s	$fa0, $fa0, $fa0
+; LA64-NEXT:    ret
+  %y1 = freeze half undef
+  %t1 = fadd half %y1, %y1
+  ret half %t1
+}

@wangleiat
Copy link
Contributor

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.

@yxd-ym
Copy link
Contributor Author

yxd-ym commented Sep 9, 2024

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?

Copy link
Contributor

@wangleiat wangleiat left a comment

Choose a reason for hiding this comment

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

LGTM

@yxd-ym
Copy link
Contributor Author

yxd-ym commented Sep 10, 2024

cc @heiher @SixWeining

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

@heiher
Copy link
Member

heiher commented Sep 10, 2024

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.

llvm/test/CodeGen/LoongArch/fp16-promote.ll Outdated Show resolved Hide resolved
@SixWeining
Copy link
Contributor

Should the commit message be updated?

@yxd-ym
Copy link
Contributor Author

yxd-ym commented Sep 12, 2024

Should the commit message be updated?

Updated.

@SixWeining SixWeining merged commit 13280d9 into llvm:main Sep 13, 2024
8 checks passed
Copy link

@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
Copy link
Contributor Author

yxd-ym commented Sep 16, 2024

/cherry-pick 13280d9

@llvmbot
Copy link
Collaborator

llvmbot commented Sep 16, 2024

/cherry-pick 13280d9

Error: Command failed due to missing milestone.

@nikic nikic added this to the LLVM 19.X Release milestone Sep 18, 2024
@nikic
Copy link
Contributor

nikic commented Sep 18, 2024

/cherry-pick 13280d9

@nikic
Copy link
Contributor

nikic commented Sep 18, 2024

Does this also fix #97975 on loongarch?

llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Sep 18, 2024
…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`:
- llvm#93894
- llvm#94456

Also see: other float promotion FREEZE handling
-
llvm@0019c2f

(cherry picked from commit 13280d9)
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 18, 2024

/pull-request #109093

andrewrk added a commit to ziglang/zig-bootstrap that referenced this pull request Sep 18, 2024
@heiher
Copy link
Member

heiher commented Sep 20, 2024

Does this also fix #97975 on loongarch?

Yes. it also fix #97981

heiher pushed a commit to llvmbot/llvm-project that referenced this pull request Oct 19, 2024
…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`:
- llvm#93894
- llvm#94456

Also see: other float promotion FREEZE handling
-
llvm@0019c2f

(cherry picked from commit 13280d9)
@Felipe940402
Copy link

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

Download

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

8 participants