ConstantsTest.cpp revision 023d97d70305dfe5a1a24659496ef95dc6bf3d39
1c779e96158cbac4c62df8e2053ab6a933eba5868Chandler Carruth//===- llvm/unittest/IR/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 124655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy StepanovTEST(ConstantsTest, PointerCast) { 125655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov LLVMContext &C(getGlobalContext()); 126655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov Type *Int8PtrTy = Type::getInt8PtrTy(C); 127655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov Type *Int32PtrTy = Type::getInt32PtrTy(C); 128655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov Type *Int64Ty = Type::getInt64Ty(C); 129655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov VectorType *Int8PtrVecTy = VectorType::get(Int8PtrTy, 4); 130655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov VectorType *Int32PtrVecTy = VectorType::get(Int32PtrTy, 4); 131655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov VectorType *Int64VecTy = VectorType::get(Int64Ty, 4); 132655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov 133655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov // ptrtoint i8* to i64 134655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov EXPECT_EQ(Constant::getNullValue(Int64Ty), 135655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov ConstantExpr::getPointerCast( 136655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov Constant::getNullValue(Int8PtrTy), Int64Ty)); 137655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov 138655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov // bitcast i8* to i32* 139655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov EXPECT_EQ(Constant::getNullValue(Int32PtrTy), 140655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov ConstantExpr::getPointerCast( 141655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov Constant::getNullValue(Int8PtrTy), Int32PtrTy)); 142655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov 143655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov // ptrtoint <4 x i8*> to <4 x i64> 144655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov EXPECT_EQ(Constant::getNullValue(Int64VecTy), 145655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov ConstantExpr::getPointerCast( 146655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov Constant::getNullValue(Int8PtrVecTy), Int64VecTy)); 147655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov 148655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov // bitcast <4 x i8*> to <4 x i32*> 149655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov EXPECT_EQ(Constant::getNullValue(Int32PtrVecTy), 150655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov ConstantExpr::getPointerCast( 151655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov Constant::getNullValue(Int8PtrVecTy), Int32PtrVecTy)); 152655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov} 153655578f8b5275e7c59b87d4709b0d56b2621caacEvgeniy Stepanov 1546bf3e46aa87d0cb6044f2282a40411211bf95a5dNAKAMURA Takumi#define CHECK(x, y) { \ 1556bf3e46aa87d0cb6044f2282a40411211bf95a5dNAKAMURA Takumi std::string __s; \ 1566bf3e46aa87d0cb6044f2282a40411211bf95a5dNAKAMURA Takumi raw_string_ostream __o(__s); \ 1576bf3e46aa87d0cb6044f2282a40411211bf95a5dNAKAMURA Takumi Instruction *__I = cast<ConstantExpr>(x)->getAsInstruction(); \ 1586bf3e46aa87d0cb6044f2282a40411211bf95a5dNAKAMURA Takumi __I->print(__o); \ 1596bf3e46aa87d0cb6044f2282a40411211bf95a5dNAKAMURA Takumi delete __I; \ 1606bf3e46aa87d0cb6044f2282a40411211bf95a5dNAKAMURA Takumi __o.flush(); \ 1616bf3e46aa87d0cb6044f2282a40411211bf95a5dNAKAMURA Takumi EXPECT_EQ(std::string(" <badref> = " y), __s); \ 162b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy } 163b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 164b9478c2aef060aa6b0ede41c05859c34b1527bf8James MolloyTEST(ConstantsTest, AsInstructionsTest) { 165023d97d70305dfe5a1a24659496ef95dc6bf3d39NAKAMURA Takumi OwningPtr<Module> M(new Module("MyModule", getGlobalContext())); 166b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 167b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Type *Int64Ty = Type::getInt64Ty(getGlobalContext()); 168b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Type *Int32Ty = Type::getInt32Ty(getGlobalContext()); 169b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Type *Int16Ty = Type::getInt16Ty(getGlobalContext()); 170b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Type *Int1Ty = Type::getInt1Ty(getGlobalContext()); 171b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Type *FloatTy = Type::getFloatTy(getGlobalContext()); 172b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Type *DoubleTy = Type::getDoubleTy(getGlobalContext()); 173b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 174b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Constant *Global = M->getOrInsertGlobal("dummy", 175b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy PointerType::getUnqual(Int32Ty)); 176b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Constant *Global2 = M->getOrInsertGlobal("dummy2", 177b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy PointerType::getUnqual(Int32Ty)); 178b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 179b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Constant *P0 = ConstantExpr::getPtrToInt(Global, Int32Ty); 180b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Constant *P1 = ConstantExpr::getUIToFP(P0, FloatTy); 181b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Constant *P2 = ConstantExpr::getUIToFP(P0, DoubleTy); 182b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Constant *P3 = ConstantExpr::getTrunc(P0, Int1Ty); 183b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Constant *P4 = ConstantExpr::getPtrToInt(Global2, Int32Ty); 184b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Constant *P5 = ConstantExpr::getUIToFP(P4, FloatTy); 185b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Constant *P6 = ConstantExpr::getBitCast(P4, VectorType::get(Int16Ty, 2)); 186b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 187b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Constant *One = ConstantInt::get(Int32Ty, 1); 188b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 189b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy #define P0STR "ptrtoint (i32** @dummy to i32)" 190b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy #define P1STR "uitofp (i32 ptrtoint (i32** @dummy to i32) to float)" 191b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy #define P2STR "uitofp (i32 ptrtoint (i32** @dummy to i32) to double)" 192b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy #define P3STR "ptrtoint (i32** @dummy to i1)" 193b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy #define P4STR "ptrtoint (i32** @dummy2 to i32)" 194b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy #define P5STR "uitofp (i32 ptrtoint (i32** @dummy2 to i32) to float)" 195b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy #define P6STR "bitcast (i32 ptrtoint (i32** @dummy2 to i32) to <2 x i16>)" 196b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 197b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getNeg(P0), "sub i32 0, " P0STR); 198b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getFNeg(P1), "fsub float -0.000000e+00, " P1STR); 199b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getNot(P0), "xor i32 " P0STR ", -1"); 200b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getAdd(P0, P0), "add i32 " P0STR ", " P0STR); 201b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getAdd(P0, P0, false, true), "add nsw i32 " P0STR ", " 202b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy P0STR); 203b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getAdd(P0, P0, true, true), "add nuw nsw i32 " P0STR ", " 204b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy P0STR); 205b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getFAdd(P1, P1), "fadd float " P1STR ", " P1STR); 206b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getSub(P0, P0), "sub i32 " P0STR ", " P0STR); 207b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getFSub(P1, P1), "fsub float " P1STR ", " P1STR); 208b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getMul(P0, P0), "mul i32 " P0STR ", " P0STR); 209b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getFMul(P1, P1), "fmul float " P1STR ", " P1STR); 210b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getUDiv(P0, P0), "udiv i32 " P0STR ", " P0STR); 211b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getSDiv(P0, P0), "sdiv i32 " P0STR ", " P0STR); 212b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getFDiv(P1, P1), "fdiv float " P1STR ", " P1STR); 213b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getURem(P0, P0), "urem i32 " P0STR ", " P0STR); 214b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getSRem(P0, P0), "srem i32 " P0STR ", " P0STR); 215b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getFRem(P1, P1), "frem float " P1STR ", " P1STR); 216b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getAnd(P0, P0), "and i32 " P0STR ", " P0STR); 217b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getOr(P0, P0), "or i32 " P0STR ", " P0STR); 218b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getXor(P0, P0), "xor i32 " P0STR ", " P0STR); 219b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getShl(P0, P0), "shl i32 " P0STR ", " P0STR); 220b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getShl(P0, P0, true), "shl nuw i32 " P0STR ", " P0STR); 221b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getShl(P0, P0, false, true), "shl nsw i32 " P0STR ", " 222b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy P0STR); 223b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getLShr(P0, P0, false), "lshr i32 " P0STR ", " P0STR); 224b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getLShr(P0, P0, true), "lshr exact i32 " P0STR ", " P0STR); 225b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getAShr(P0, P0, false), "ashr i32 " P0STR ", " P0STR); 226b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getAShr(P0, P0, true), "ashr exact i32 " P0STR ", " P0STR); 227b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 228b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getSExt(P0, Int64Ty), "sext i32 " P0STR " to i64"); 229b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getZExt(P0, Int64Ty), "zext i32 " P0STR " to i64"); 230b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getFPTrunc(P2, FloatTy), "fptrunc double " P2STR 231b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy " to float"); 232b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getFPExtend(P1, DoubleTy), "fpext float " P1STR 233b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy " to double"); 234b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 235b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getExactUDiv(P0, P0), "udiv exact i32 " P0STR ", " P0STR); 236b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 237b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getSelect(P3, P0, P4), "select i1 " P3STR ", i32 " P0STR 238b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy ", i32 " P4STR); 239b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getICmp(CmpInst::ICMP_EQ, P0, P4), "icmp eq i32 " P0STR 240b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy ", " P4STR); 241b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getFCmp(CmpInst::FCMP_ULT, P1, P5), "fcmp ult float " 242b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy P1STR ", " P5STR); 243b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 244b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy std::vector<Constant*> V; 245b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy V.push_back(One); 246b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy // FIXME: getGetElementPtr() actually creates an inbounds ConstantGEP, 247b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy // not a normal one! 248b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy //CHECK(ConstantExpr::getGetElementPtr(Global, V, false), 249b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy // "getelementptr i32** @dummy, i32 1"); 250b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getInBoundsGetElementPtr(Global, V), 251b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy "getelementptr inbounds i32** @dummy, i32 1"); 252b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 253b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy CHECK(ConstantExpr::getExtractElement(P6, One), "extractelement <2 x i16> " 254b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy P6STR ", i32 1"); 255b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy} 256b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 257b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy#undef CHECK 258b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 2592e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman} // end anonymous namespace 2602e734269e3f354e52bd9e55d791e1885aa7d4cd8Misha Brukman} // end namespace llvm 261