[llvm] [IR] Fix crash when creating llvm.powi.* by `CreateBinaryIntrinsic` (PR #67263)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 24 05:07:11 PDT 2023
https://github.com/dtcxzyw created https://github.com/llvm/llvm-project/pull/67263
This patch fixes crashes in #67236 when creating `llvm.powi.*` via `IRBuilderBase::CreateBinaryIntrinsic`.
>From b9ad9eb343a3608fe78276715397f9cbeac87275 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Sun, 24 Sep 2023 19:56:35 +0800
Subject: [PATCH] [IR] Fix crash when creating llvm.powi.* by
`CreateBinaryIntrinsic`
---
llvm/lib/IR/IRBuilder.cpp | 3 ++-
llvm/unittests/IR/IRBuilderTest.cpp | 15 ++++++++++++++-
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBuilder.cpp
index b321d8b325fe0be..0c2016662b4d72a 100644
--- a/llvm/lib/IR/IRBuilder.cpp
+++ b/llvm/lib/IR/IRBuilder.cpp
@@ -934,7 +934,8 @@ CallInst *IRBuilderBase::CreateBinaryIntrinsic(Intrinsic::ID ID, Value *LHS,
Instruction *FMFSource,
const Twine &Name) {
Module *M = BB->getModule();
- Function *Fn = Intrinsic::getDeclaration(M, ID, { LHS->getType() });
+ Function *Fn =
+ Intrinsic::getDeclaration(M, ID, {LHS->getType(), RHS->getType()});
return createCallHelper(Fn, {LHS, RHS}, Name, FMFSource);
}
diff --git a/llvm/unittests/IR/IRBuilderTest.cpp b/llvm/unittests/IR/IRBuilderTest.cpp
index ef5f974419029d4..aedc60fbe8d2380 100644
--- a/llvm/unittests/IR/IRBuilderTest.cpp
+++ b/llvm/unittests/IR/IRBuilderTest.cpp
@@ -55,12 +55,13 @@ class IRBuilderTest : public testing::Test {
TEST_F(IRBuilderTest, Intrinsics) {
IRBuilder<> Builder(BB);
- Value *V;
+ Value *V, *IV;
Instruction *I;
CallInst *Call;
IntrinsicInst *II;
V = Builder.CreateLoad(GV->getValueType(), GV);
+ IV = Builder.getInt32(2);
I = cast<Instruction>(Builder.CreateFAdd(V, V));
I->setHasNoInfs(true);
I->setHasNoNaNs(false);
@@ -109,6 +110,18 @@ TEST_F(IRBuilderTest, Intrinsics) {
EXPECT_TRUE(II->hasNoInfs());
EXPECT_FALSE(II->hasNoNaNs());
+ Call = Builder.CreateBinaryIntrinsic(Intrinsic::powi, V, IV);
+ II = cast<IntrinsicInst>(Call);
+ EXPECT_EQ(II->getIntrinsicID(), Intrinsic::powi);
+ EXPECT_FALSE(II->hasNoInfs());
+ EXPECT_FALSE(II->hasNoNaNs());
+
+ Call = Builder.CreateBinaryIntrinsic(Intrinsic::powi, V, IV, I);
+ II = cast<IntrinsicInst>(Call);
+ EXPECT_EQ(II->getIntrinsicID(), Intrinsic::powi);
+ EXPECT_TRUE(II->hasNoInfs());
+ EXPECT_FALSE(II->hasNoNaNs());
+
Call = Builder.CreateIntrinsic(Intrinsic::fma, {V->getType()}, {V, V, V});
II = cast<IntrinsicInst>(Call);
EXPECT_EQ(II->getIntrinsicID(), Intrinsic::fma);
More information about the llvm-commits
mailing list