Skip to content

[ConstantFold] Fix result type when folding powi.f16 #98681

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

Merged
merged 4 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions llvm/lib/Analysis/ConstantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
11 changes: 11 additions & 0 deletions llvm/test/Transforms/InstSimplify/ConstProp/pr98665.ll
Original file line number Diff line number Diff line change
@@ -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
}
Loading