Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
[IRBuilder] fix CreateMaxNum to actually produce maxnum (PR36454)
Browse files Browse the repository at this point in the history
The bug was introduced here:
https://reviews.llvm.org/rL296409
...but the patch doesn't use maxnum and nothing else in 
trunk has tried since then, so the bug went unnoticed.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@325607 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rotateright committed Feb 20, 2018
1 parent 1837dbf commit e271f8c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/llvm/IR/IRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ class IRBuilderBase {

/// Create call to the maxnum intrinsic.
CallInst *CreateMaxNum(Value *LHS, Value *RHS, const Twine &Name = "") {
return CreateBinaryIntrinsic(Intrinsic::minnum, LHS, RHS, Name);
return CreateBinaryIntrinsic(Intrinsic::maxnum, LHS, RHS, Name);
}

private:
Expand Down
17 changes: 17 additions & 0 deletions unittests/IR/IRBuilderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ class IRBuilderTest : public testing::Test {
GlobalVariable *GV;
};

TEST_F(IRBuilderTest, Intrinsics) {
IRBuilder<> Builder(BB);
Value *V;
CallInst *Call;
IntrinsicInst *II;

V = Builder.CreateLoad(GV);

Call = Builder.CreateMinNum(V, V);
II = cast<IntrinsicInst>(Call);
EXPECT_EQ(II->getIntrinsicID(), Intrinsic::minnum);

Call = Builder.CreateMaxNum(V, V);
II = cast<IntrinsicInst>(Call);
EXPECT_EQ(II->getIntrinsicID(), Intrinsic::maxnum);
}

TEST_F(IRBuilderTest, Lifetime) {
IRBuilder<> Builder(BB);
AllocaInst *Var1 = Builder.CreateAlloca(Builder.getInt8Ty());
Expand Down

0 comments on commit e271f8c

Please sign in to comment.