ConstantsTest.cpp revision 0b8c9a80f20772c3793201ab5b251d3520b9cea3
12e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman//===- llvm/unittest/VMCore/ConstantsTest.cpp - Constants unit tests ------===// 22e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman// 32e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman// The LLVM Compiler Infrastructure 42e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman// 52e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman// This file is distributed under the University of Illinois Open Source 62e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman// License. See LICENSE.TXT for details. 72e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman// 82e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman//===----------------------------------------------------------------------===// 92e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 100b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Constants.h" 110b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/DerivedTypes.h" 120b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/InstrTypes.h" 130b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Instruction.h" 140b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/LLVMContext.h" 150b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Module.h" 162e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman#include "gtest/gtest.h" 172e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 182e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukmannamespace llvm { 192e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukmannamespace { 202e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 212e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha BrukmanTEST(ConstantsTest, Integer_i1) { 22db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner IntegerType* Int1 = IntegerType::get(getGlobalContext(), 1); 23eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson Constant* One = ConstantInt::get(Int1, 1, true); 24eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson Constant* Zero = ConstantInt::get(Int1, 0); 25eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson Constant* NegOne = ConstantInt::get(Int1, static_cast<uint64_t>(-1), true); 26eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson EXPECT_EQ(NegOne, ConstantInt::getSigned(Int1, -1)); 279e9a0d5fc26878e51a58a8b57900fcbf952c2691Owen Anderson Constant* Undef = UndefValue::get(Int1); 282e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 292e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // Input: @b = constant i1 add(i1 1 , i1 1) 302e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // Output: @b = constant i1 false 319138b1909a4c2d88aa88f807b296356f09206e87Benjamin Kramer EXPECT_EQ(Zero, ConstantExpr::getAdd(One, One)); 322e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 332e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @c = constant i1 add(i1 -1, i1 1) 342e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @c = constant i1 false 359138b1909a4c2d88aa88f807b296356f09206e87Benjamin Kramer EXPECT_EQ(Zero, ConstantExpr::getAdd(NegOne, One)); 362e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 372e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @d = constant i1 add(i1 -1, i1 -1) 382e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @d = constant i1 false 399138b1909a4c2d88aa88f807b296356f09206e87Benjamin Kramer EXPECT_EQ(Zero, ConstantExpr::getAdd(NegOne, NegOne)); 402e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 412e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @e = constant i1 sub(i1 -1, i1 1) 422e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @e = constant i1 false 439138b1909a4c2d88aa88f807b296356f09206e87Benjamin Kramer EXPECT_EQ(Zero, ConstantExpr::getSub(NegOne, One)); 442e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 452e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @f = constant i1 sub(i1 1 , i1 -1) 462e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @f = constant i1 false 479138b1909a4c2d88aa88f807b296356f09206e87Benjamin Kramer EXPECT_EQ(Zero, ConstantExpr::getSub(One, NegOne)); 482e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 492e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @g = constant i1 sub(i1 1 , i1 1) 502e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @g = constant i1 false 519138b1909a4c2d88aa88f807b296356f09206e87Benjamin Kramer EXPECT_EQ(Zero, ConstantExpr::getSub(One, One)); 522e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 532e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @h = constant i1 shl(i1 1 , i1 1) ; undefined 542e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @h = constant i1 undef 559138b1909a4c2d88aa88f807b296356f09206e87Benjamin Kramer EXPECT_EQ(Undef, ConstantExpr::getShl(One, One)); 562e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 572e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @i = constant i1 shl(i1 1 , i1 0) 582e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @i = constant i1 true 599138b1909a4c2d88aa88f807b296356f09206e87Benjamin Kramer EXPECT_EQ(One, ConstantExpr::getShl(One, Zero)); 602e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 612e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @j = constant i1 lshr(i1 1, i1 1) ; undefined 622e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @j = constant i1 undef 639138b1909a4c2d88aa88f807b296356f09206e87Benjamin Kramer EXPECT_EQ(Undef, ConstantExpr::getLShr(One, One)); 642e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 652e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @m = constant i1 ashr(i1 1, i1 1) ; undefined 662e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @m = constant i1 undef 679138b1909a4c2d88aa88f807b296356f09206e87Benjamin Kramer EXPECT_EQ(Undef, ConstantExpr::getAShr(One, One)); 682e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 692e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @n = constant i1 mul(i1 -1, i1 1) 702e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @n = constant i1 true 719138b1909a4c2d88aa88f807b296356f09206e87Benjamin Kramer EXPECT_EQ(One, ConstantExpr::getMul(NegOne, One)); 722e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 732e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @o = constant i1 sdiv(i1 -1, i1 1) ; overflow 742e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @o = constant i1 true 759138b1909a4c2d88aa88f807b296356f09206e87Benjamin Kramer EXPECT_EQ(One, ConstantExpr::getSDiv(NegOne, One)); 762e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 772e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @p = constant i1 sdiv(i1 1 , i1 -1); overflow 782e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @p = constant i1 true 799138b1909a4c2d88aa88f807b296356f09206e87Benjamin Kramer EXPECT_EQ(One, ConstantExpr::getSDiv(One, NegOne)); 802e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 812e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @q = constant i1 udiv(i1 -1, i1 1) 822e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @q = constant i1 true 839138b1909a4c2d88aa88f807b296356f09206e87Benjamin Kramer EXPECT_EQ(One, ConstantExpr::getUDiv(NegOne, One)); 842e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 852e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @r = constant i1 udiv(i1 1, i1 -1) 862e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @r = constant i1 true 879138b1909a4c2d88aa88f807b296356f09206e87Benjamin Kramer EXPECT_EQ(One, ConstantExpr::getUDiv(One, NegOne)); 882e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 892e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @s = constant i1 srem(i1 -1, i1 1) ; overflow 902e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @s = constant i1 false 919138b1909a4c2d88aa88f807b296356f09206e87Benjamin Kramer EXPECT_EQ(Zero, ConstantExpr::getSRem(NegOne, One)); 922e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 932e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @t = constant i1 urem(i1 -1, i1 1) 942e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @t = constant i1 false 959138b1909a4c2d88aa88f807b296356f09206e87Benjamin Kramer EXPECT_EQ(Zero, ConstantExpr::getURem(NegOne, One)); 962e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 972e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @u = constant i1 srem(i1 1, i1 -1) ; overflow 982e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman // @u = constant i1 false 999138b1909a4c2d88aa88f807b296356f09206e87Benjamin Kramer EXPECT_EQ(Zero, ConstantExpr::getSRem(One, NegOne)); 1002e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman} 1012e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman 102f3b0aac1902d6e01ed9a633f4a93c26317b43835Chris LattnerTEST(ConstantsTest, IntSigns) { 103db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner IntegerType* Int8Ty = Type::getInt8Ty(getGlobalContext()); 104eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson EXPECT_EQ(100, ConstantInt::get(Int8Ty, 100, false)->getSExtValue()); 105eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson EXPECT_EQ(100, ConstantInt::get(Int8Ty, 100, true)->getSExtValue()); 106eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson EXPECT_EQ(100, ConstantInt::getSigned(Int8Ty, 100)->getSExtValue()); 107eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson EXPECT_EQ(-50, ConstantInt::get(Int8Ty, 206)->getSExtValue()); 108eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson EXPECT_EQ(-50, ConstantInt::getSigned(Int8Ty, -50)->getSExtValue()); 109eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson EXPECT_EQ(206U, ConstantInt::getSigned(Int8Ty, -50)->getZExtValue()); 110f3b0aac1902d6e01ed9a633f4a93c26317b43835Chris Lattner 111f3b0aac1902d6e01ed9a633f4a93c26317b43835Chris Lattner // Overflow is handled by truncation. 112eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson EXPECT_EQ(0x3b, ConstantInt::get(Int8Ty, 0x13b)->getSExtValue()); 113f3b0aac1902d6e01ed9a633f4a93c26317b43835Chris Lattner} 114f3b0aac1902d6e01ed9a633f4a93c26317b43835Chris Lattner 115e562dba845265b5577699eb857fead1ea0f7905bChris LattnerTEST(ConstantsTest, FP128Test) { 116db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Type *FP128Ty = Type::getFP128Ty(getGlobalContext()); 117e562dba845265b5577699eb857fead1ea0f7905bChris Lattner 118db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner IntegerType *Int128Ty = Type::getIntNTy(getGlobalContext(), 128); 119e562dba845265b5577699eb857fead1ea0f7905bChris Lattner Constant *Zero128 = Constant::getNullValue(Int128Ty); 120e562dba845265b5577699eb857fead1ea0f7905bChris Lattner Constant *X = ConstantExpr::getUIToFP(Zero128, FP128Ty); 121e562dba845265b5577699eb857fead1ea0f7905bChris Lattner EXPECT_TRUE(isa<ConstantFP>(X)); 122e562dba845265b5577699eb857fead1ea0f7905bChris Lattner} 123e562dba845265b5577699eb857fead1ea0f7905bChris Lattner 124b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy#define CHECK(x, y) { \ 125b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy std::string __s; \ 126b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy raw_string_ostream __o(__s); \ 127b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy cast<ConstantExpr>(x)->getAsInstruction()->print(__o); \ 128b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy __o.flush(); \ 129b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy EXPECT_EQ(std::string(" <badref> = " y), __s); \ 130b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy } 131b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 132b9478c2aef060aa6b0ede41c05859c34b1527bf8James MolloyTEST(ConstantsTest, AsInstructionsTest) { 133b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Module *M = new Module("MyModule", getGlobalContext()); 134b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 135b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Type *Int64Ty = Type::getInt64Ty(getGlobalContext()); 136b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Type *Int32Ty = Type::getInt32Ty(getGlobalContext()); 137b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Type *Int16Ty = Type::getInt16Ty(getGlobalContext()); 138b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Type *Int1Ty = Type::getInt1Ty(getGlobalContext()); 139b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Type *FloatTy = Type::getFloatTy(getGlobalContext()); 140b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Type *DoubleTy = Type::getDoubleTy(getGlobalContext()); 141b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 142b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Constant *Global = M->getOrInsertGlobal("dummy", 143b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy PointerType::getUnqual(Int32Ty)); 144b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Constant *Global2 = M->getOrInsertGlobal("dummy2", 145b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy PointerType::getUnqual(Int32Ty)); 146b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 147b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Constant *P0 = ConstantExpr::getPtrToInt(Global, Int32Ty); 148b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Constant *P1 = ConstantExpr::getUIToFP(P0, FloatTy); 149b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Constant *P2 = ConstantExpr::getUIToFP(P0, DoubleTy); 150b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Constant *P3 = ConstantExpr::getTrunc(P0, Int1Ty); 151b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Constant *P4 = ConstantExpr::getPtrToInt(Global2, Int32Ty); 152b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Constant *P5 = ConstantExpr::getUIToFP(P4, FloatTy); 153b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Constant *P6 = ConstantExpr::getBitCast(P4, VectorType::get(Int16Ty, 2)); 154b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 155b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Constant *One = ConstantInt::get(Int32Ty, 1); 156b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 157b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy #define P0STR "ptrtoint (i32** @dummy to i32)" 158b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy #define P1STR "uitofp (i32 ptrtoint (i32** @dummy to i32) to float)" 159b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy #define P2STR "uitofp (i32 ptrtoint (i32** @dummy to i32) to double)" 160b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy #define P3STR "ptrtoint (i32** @dummy to i1)" 161b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy #define P4STR "ptrtoint (i32** @dummy2 to i32)" 162b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy #define P5STR "uitofp (i32 ptrtoint (i32** @dummy2 to i32) to float)" 163b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy #define P6STR "bitcast (i32 ptrtoint (i32** @dummy2 to i32) to <2 x i16>)" 164b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 165b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getNeg(P0), "sub i32 0, " P0STR); 166b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getFNeg(P1), "fsub float -0.000000e+00, " P1STR); 167b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getNot(P0), "xor i32 " P0STR ", -1"); 168b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getAdd(P0, P0), "add i32 " P0STR ", " P0STR); 169b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getAdd(P0, P0, false, true), "add nsw i32 " P0STR ", " 170b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy P0STR); 171b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getAdd(P0, P0, true, true), "add nuw nsw i32 " P0STR ", " 172b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy P0STR); 173b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getFAdd(P1, P1), "fadd float " P1STR ", " P1STR); 174b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getSub(P0, P0), "sub i32 " P0STR ", " P0STR); 175b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getFSub(P1, P1), "fsub float " P1STR ", " P1STR); 176b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getMul(P0, P0), "mul i32 " P0STR ", " P0STR); 177b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getFMul(P1, P1), "fmul float " P1STR ", " P1STR); 178b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getUDiv(P0, P0), "udiv i32 " P0STR ", " P0STR); 179b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getSDiv(P0, P0), "sdiv i32 " P0STR ", " P0STR); 180b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getFDiv(P1, P1), "fdiv float " P1STR ", " P1STR); 181b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getURem(P0, P0), "urem i32 " P0STR ", " P0STR); 182b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getSRem(P0, P0), "srem i32 " P0STR ", " P0STR); 183b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getFRem(P1, P1), "frem float " P1STR ", " P1STR); 184b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getAnd(P0, P0), "and i32 " P0STR ", " P0STR); 185b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getOr(P0, P0), "or i32 " P0STR ", " P0STR); 186b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getXor(P0, P0), "xor i32 " P0STR ", " P0STR); 187b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getShl(P0, P0), "shl i32 " P0STR ", " P0STR); 188b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getShl(P0, P0, true), "shl nuw i32 " P0STR ", " P0STR); 189b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getShl(P0, P0, false, true), "shl nsw i32 " P0STR ", " 190b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy P0STR); 191b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getLShr(P0, P0, false), "lshr i32 " P0STR ", " P0STR); 192b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getLShr(P0, P0, true), "lshr exact i32 " P0STR ", " P0STR); 193b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getAShr(P0, P0, false), "ashr i32 " P0STR ", " P0STR); 194b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getAShr(P0, P0, true), "ashr exact i32 " P0STR ", " P0STR); 195b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 196b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getSExt(P0, Int64Ty), "sext i32 " P0STR " to i64"); 197b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getZExt(P0, Int64Ty), "zext i32 " P0STR " to i64"); 198b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getFPTrunc(P2, FloatTy), "fptrunc double " P2STR 199b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy " to float"); 200b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getFPExtend(P1, DoubleTy), "fpext float " P1STR 201b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy " to double"); 202b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 203b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getExactUDiv(P0, P0), "udiv exact i32 " P0STR ", " P0STR); 204b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 205b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getSelect(P3, P0, P4), "select i1 " P3STR ", i32 " P0STR 206b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy ", i32 " P4STR); 207b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getICmp(CmpInst::ICMP_EQ, P0, P4), "icmp eq i32 " P0STR 208b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy ", " P4STR); 209b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getFCmp(CmpInst::FCMP_ULT, P1, P5), "fcmp ult float " 210b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy P1STR ", " P5STR); 211b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 212b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy std::vector<Constant*> V; 213b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy V.push_back(One); 214b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy // FIXME: getGetElementPtr() actually creates an inbounds ConstantGEP, 215b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy // not a normal one! 216b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy //CHECK(ConstantExpr::getGetElementPtr(Global, V, false), 217b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy // "getelementptr i32** @dummy, i32 1"); 218b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getInBoundsGetElementPtr(Global, V), 219b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy "getelementptr inbounds i32** @dummy, i32 1"); 220b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 221b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getExtractElement(P6, One), "extractelement <2 x i16> " 222b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy P6STR ", i32 1"); 223b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy} 224b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 225b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy#undef CHECK 226b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 2272e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman} // end anonymous namespace 2282e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman} // end namespace llvm 229