[llvm] [loongarch][DAG][FREEZE] Fix crash when FREEZE a half(f16) type on loongarch (PR #107791)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 8 17:50:02 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-loongarch
Author: YANG Xudong (yxd-ym)
<details>
<summary>Changes</summary>
For zig with LLVM 19.1.0rc4, we are seeing the following error when bootstrapping a `loongarch64-linux-musl` target.
https://github.com/ziglang/zig-bootstrap/issues/164#issuecomment-2332357069
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`:
- https://github.com/llvm/llvm-project/issues/93894
- https://github.com/llvm/llvm-project/pull/94456
Also see: other float promotion FREEZE handling
- https://github.com/llvm/llvm-project/commit/0019c2f194a5e1f4cd65c5284e204328cc40ab3d
---
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
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
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/107791
More information about the llvm-commits
mailing list