[ConstantFold] Fix result type when folding powi.f16#98681
[ConstantFold] Fix result type when folding powi.f16#98681
Conversation
|
@llvm/pr-subscribers-llvm-analysis Author: Yingwei Zheng (dtcxzyw) ChangesFixes #98665. Full diff: https://github.com/llvm/llvm-project/pull/98681.diff 2 Files Affected:
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 962880f68f076..b86f91edeb5b9 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2760,11 +2760,13 @@ static Constant *ConstantFoldIntrinsicCall2(Intrinsic::ID IntrinsicID, Type *Ty,
if (!Ty->isHalfTy() && !Ty->isFloatTy() && !Ty->isDoubleTy())
return nullptr;
- if (IntrinsicID == Intrinsic::powi && Ty->isHalfTy())
- return ConstantFP::get(
- Ty->getContext(),
- APFloat((float)std::pow((float)Op1V.convertToDouble(),
- (int)Op2C->getZExtValue())));
+ if (IntrinsicID == Intrinsic::powi && Ty->isHalfTy()) {
+ APFloat Res((float)std::pow((float)Op1V.convertToDouble(),
+ (int)Op2C->getZExtValue()));
+ bool unused;
+ Res.convert(APFloat::IEEEhalf(), APFloat::rmNearestTiesToEven, &unused);
+ return ConstantFP::get(Ty->getContext(), Res);
+ }
if (IntrinsicID == Intrinsic::powi && Ty->isFloatTy())
return ConstantFP::get(
Ty->getContext(),
diff --git a/llvm/test/Transforms/InstSimplify/ConstProp/pr98665.ll b/llvm/test/Transforms/InstSimplify/ConstProp/pr98665.ll
new file mode 100644
index 0000000000000..8b7d361840936
--- /dev/null
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/pr98665.ll
@@ -0,0 +1,11 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
+; Make sure that the type is correct after constant folding
+
+define half @pr98665() {
+; CHECK-LABEL: define half @pr98665() {
+; CHECK-NEXT: ret half 0xH3C00
+;
+ %x = call half @llvm.powi.f16.i32(half 0xH3C00, i32 1)
+ ret half %x
+}
|
|
@llvm/pr-subscribers-llvm-transforms Author: Yingwei Zheng (dtcxzyw) ChangesFixes #98665. Full diff: https://github.com/llvm/llvm-project/pull/98681.diff 2 Files Affected:
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 962880f68f076..b86f91edeb5b9 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2760,11 +2760,13 @@ static Constant *ConstantFoldIntrinsicCall2(Intrinsic::ID IntrinsicID, Type *Ty,
if (!Ty->isHalfTy() && !Ty->isFloatTy() && !Ty->isDoubleTy())
return nullptr;
- if (IntrinsicID == Intrinsic::powi && Ty->isHalfTy())
- return ConstantFP::get(
- Ty->getContext(),
- APFloat((float)std::pow((float)Op1V.convertToDouble(),
- (int)Op2C->getZExtValue())));
+ if (IntrinsicID == Intrinsic::powi && Ty->isHalfTy()) {
+ APFloat Res((float)std::pow((float)Op1V.convertToDouble(),
+ (int)Op2C->getZExtValue()));
+ bool unused;
+ Res.convert(APFloat::IEEEhalf(), APFloat::rmNearestTiesToEven, &unused);
+ return ConstantFP::get(Ty->getContext(), Res);
+ }
if (IntrinsicID == Intrinsic::powi && Ty->isFloatTy())
return ConstantFP::get(
Ty->getContext(),
diff --git a/llvm/test/Transforms/InstSimplify/ConstProp/pr98665.ll b/llvm/test/Transforms/InstSimplify/ConstProp/pr98665.ll
new file mode 100644
index 0000000000000..8b7d361840936
--- /dev/null
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/pr98665.ll
@@ -0,0 +1,11 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
+; Make sure that the type is correct after constant folding
+
+define half @pr98665() {
+; CHECK-LABEL: define half @pr98665() {
+; CHECK-NEXT: ret half 0xH3C00
+;
+ %x = call half @llvm.powi.f16.i32(half 0xH3C00, i32 1)
+ ret half %x
+}
|
nikic
left a comment
There was a problem hiding this comment.
LGTM, though this code could really do with some cleanup. Why are there three different ifs checking for IntrinsicID == Intrinsic::powi when there is a perfectly good switch just before it?
|
dtcxzyw/llvm-opt-benchmark#961 |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/51/builds/1315 Here is the relevant piece of the build log for the reference: |
See #98860. |
The LLVM issue [1] was fixed with [2], which is included in the LLVM20 upgrade. Tests no longer fail, so enable them here. [1]: llvm/llvm-project#98681 [2]: llvm/llvm-project#98681
Enable `f16` tests for `powf` The LLVM issue [1] was fixed with [2], which is included in the LLVM20 upgrade. Tests no longer fail, so enable them here. [1]: llvm/llvm-project#98681 [2]: llvm/llvm-project#98681 try-job: aarch64-gnu
Enable `f16` tests for `powf` The LLVM issue [1] was fixed with [2], which is included in the LLVM20 upgrade. Tests no longer fail, so enable them here. [1]: llvm/llvm-project#98681 [2]: llvm/llvm-project#98681 try-job: aarch64-gnu
The LLVM issue [1] was fixed with [2], which is included in the LLVM20 upgrade. Tests no longer fail, so enable them here. [1]: llvm/llvm-project#98681 [2]: llvm/llvm-project#98681
Enable `f16` tests for `powf` The LLVM issue [1] was fixed with [2], which is included in the LLVM20 upgrade. Tests no longer fail, so enable them here. [1]: llvm/llvm-project#98681 [2]: llvm/llvm-project#98681 try-job: aarch64-gnu try-job: x86_64-gnu-aux
Enable `f16` tests for `powf` The LLVM issue [1] was fixed with [2], which is included in the LLVM20 upgrade. Tests no longer fail, so enable them here. [1]: llvm/llvm-project#98681 [2]: llvm/llvm-project#98681 try-job: aarch64-gnu try-job: x86_64-gnu-aux
Enable `f16` tests for `powf` The LLVM issue [1] was fixed with [2], which is included in the LLVM20 upgrade. Tests no longer fail, so enable them here. [1]: llvm/llvm-project#98681 [2]: llvm/llvm-project#98681 try-job: aarch64-gnu try-job: x86_64-gnu-aux
Enable `f16` tests for `powf` The LLVM issue [1] was fixed with [2], which is included in the LLVM20 upgrade. Tests no longer fail, so enable them here. [1]: llvm/llvm-project#98681 [2]: llvm/llvm-project#98681 try-job: aarch64-gnu try-job: x86_64-gnu-aux
Enable `f16` tests for `powf` The LLVM issue [1] was fixed with [2], which is included in the LLVM20 upgrade. Tests no longer fail, so enable them here. [1]: llvm/llvm-project#98681 [2]: llvm/llvm-project#98681 try-job: aarch64-gnu try-job: x86_64-gnu-aux
Enable `f16` tests for `powf` The LLVM issue [1] was fixed with [2], which is included in the LLVM20 upgrade. Tests no longer fail, so enable them here. [1]: llvm/llvm-project#98681 [2]: llvm/llvm-project#98681 try-job: aarch64-gnu try-job: x86_64-gnu-aux
Rollup merge of rust-lang#138343 - tgross35:f16-powf, r=joboet Enable `f16` tests for `powf` The LLVM issue [1] was fixed with [2], which is included in the LLVM20 upgrade. Tests no longer fail, so enable them here. [1]: llvm/llvm-project#98681 [2]: llvm/llvm-project#98681 try-job: aarch64-gnu try-job: x86_64-gnu-aux
The LLVM issue [1] was fixed with [2], which is included in the LLVM20 upgrade. Tests no longer fail, so enable them here. [1]: llvm/llvm-project#98681 [2]: llvm/llvm-project#98681
Enable `f16` tests for `powf` The LLVM issue [1] was fixed with [2], which is included in the LLVM20 upgrade. Tests no longer fail, so enable them here. [1]: llvm/llvm-project#98681 [2]: llvm/llvm-project#98681 try-job: aarch64-gnu try-job: x86_64-gnu-aux
The LLVM issue [1] was fixed with [2], which is included in the LLVM20 upgrade. Tests no longer fail, so enable them here. [1]: llvm/llvm-project#98681 [2]: llvm/llvm-project#98681
Fixes #98665.