Browse Source

[IRBuilder] fix CreateMaxNum to actually produce maxnum (PR36454)

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
Sanjay Patel 7 years ago
parent
commit
e271f8c46c
2 changed files with 18 additions and 1 deletions
  1. 1 1
      include/llvm/IR/IRBuilder.h
  2. 17 0
      unittests/IR/IRBuilderTest.cpp

+ 1 - 1
include/llvm/IR/IRBuilder.h

@@ -676,7 +676,7 @@ public:
 
   /// 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:

+ 17 - 0
unittests/IR/IRBuilderTest.cpp

@@ -48,6 +48,23 @@ protected:
   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());