blob: ce68c29612cbb5cf1d3fe892bdc5894643238b21 [file] [log] [blame]
Chris Lattner3b66ecb2003-12-28 08:19:41 +00001//===-- IntrinsicLowering.cpp - Intrinsic Lowering default implementation -===//
Misha Brukmanedf128a2005-04-21 22:36:52 +00002//
Chris Lattner3b66ecb2003-12-28 08:19:41 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanedf128a2005-04-21 22:36:52 +00007//
Chris Lattner3b66ecb2003-12-28 08:19:41 +00008//===----------------------------------------------------------------------===//
9//
Chris Lattnerb71fd782006-11-15 18:00:10 +000010// This file implements the IntrinsicLowering class.
Chris Lattner3b66ecb2003-12-28 08:19:41 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattnercf899082004-02-14 02:47:17 +000014#include "llvm/Constants.h"
Chris Lattner5fe51cc2004-02-12 17:01:09 +000015#include "llvm/DerivedTypes.h"
Chris Lattner3b66ecb2003-12-28 08:19:41 +000016#include "llvm/Module.h"
Misha Brukman47b14a42004-07-29 17:30:56 +000017#include "llvm/Instructions.h"
Andrew Lenharth691ef2b2005-05-03 17:19:30 +000018#include "llvm/Type.h"
Bill Wendlingd9fd2ac2006-11-28 02:08:17 +000019#include "llvm/CodeGen/IntrinsicLowering.h"
20#include "llvm/Support/Streams.h"
Reid Spencer6addf2c2007-01-29 17:42:06 +000021#include "llvm/Target/TargetData.h"
Chris Lattner990b8492007-02-13 06:01:22 +000022#include "llvm/ADT/SmallVector.h"
Owen Anderson718cb662007-09-07 04:06:50 +000023#include "llvm/ADT/STLExtras.h"
Chris Lattner3b66ecb2003-12-28 08:19:41 +000024using namespace llvm;
25
Jay Foad589b1ef2009-05-11 11:32:25 +000026// Return the integer value Val zero-extended or truncated (if necessary) to
27// type ITy. Any new instructions are inserted at InsertBefore.
28template<typename InsertType>
29static Value *getZExtOrTrunc(Value *Val, const IntegerType *ITy,
30 InsertType InsertPoint) {
31 const IntegerType *ValTy = cast<IntegerType>(Val->getType());
32 if (ValTy == ITy)
33 return Val;
34 Constant *CVal = dyn_cast<Constant>(Val);
35 if (ValTy->getBitWidth() < ITy->getBitWidth()) {
36 if (CVal)
37 return ConstantExpr::getZExt(CVal, ITy);
38 return new ZExtInst(Val, ITy, "", InsertPoint);
39 } else {
40 if (CVal)
41 return ConstantExpr::getTrunc(CVal, ITy);
42 return new TruncInst(Val, ITy, "", InsertPoint);
43 }
44}
45
Chris Lattner0979ca72004-05-09 04:29:57 +000046template <class ArgIt>
Chris Lattnerb76efb72007-01-07 08:12:01 +000047static void EnsureFunctionExists(Module &M, const char *Name,
48 ArgIt ArgBegin, ArgIt ArgEnd,
49 const Type *RetTy) {
50 // Insert a correctly-typed definition now.
Chris Lattner0979ca72004-05-09 04:29:57 +000051 std::vector<const Type *> ParamTys;
52 for (ArgIt I = ArgBegin; I != ArgEnd; ++I)
53 ParamTys.push_back(I->getType());
Chris Lattnerb76efb72007-01-07 08:12:01 +000054 M.getOrInsertFunction(Name, FunctionType::get(RetTy, ParamTys, false));
Chris Lattner0979ca72004-05-09 04:29:57 +000055}
56
Chris Lattner556b4a62009-02-07 22:37:06 +000057static void EnsureFPIntrinsicsExist(Module &M, Function *Fn,
58 const char *FName,
59 const char *DName, const char *LDName) {
Dale Johannesenc4342ea2008-09-22 19:51:58 +000060 // Insert definitions for all the floating point types.
Chris Lattner556b4a62009-02-07 22:37:06 +000061 switch((int)Fn->arg_begin()->getType()->getTypeID()) {
Dale Johannesenc4342ea2008-09-22 19:51:58 +000062 case Type::FloatTyID:
Chris Lattner556b4a62009-02-07 22:37:06 +000063 EnsureFunctionExists(M, FName, Fn->arg_begin(), Fn->arg_end(),
Dale Johannesenc4342ea2008-09-22 19:51:58 +000064 Type::FloatTy);
Chris Lattner556b4a62009-02-07 22:37:06 +000065 break;
Dale Johannesenc4342ea2008-09-22 19:51:58 +000066 case Type::DoubleTyID:
Chris Lattner556b4a62009-02-07 22:37:06 +000067 EnsureFunctionExists(M, DName, Fn->arg_begin(), Fn->arg_end(),
Dale Johannesenc4342ea2008-09-22 19:51:58 +000068 Type::DoubleTy);
Chris Lattner556b4a62009-02-07 22:37:06 +000069 break;
Dale Johannesenc4342ea2008-09-22 19:51:58 +000070 case Type::X86_FP80TyID:
71 case Type::FP128TyID:
72 case Type::PPC_FP128TyID:
Chris Lattner556b4a62009-02-07 22:37:06 +000073 EnsureFunctionExists(M, LDName, Fn->arg_begin(), Fn->arg_end(),
74 Fn->arg_begin()->getType());
75 break;
Dale Johannesenc4342ea2008-09-22 19:51:58 +000076 }
77}
78
Chris Lattner588e72d2004-02-15 22:16:39 +000079/// ReplaceCallWith - This function is used when we want to lower an intrinsic
80/// call to a call of an external function. This handles hard cases such as
81/// when there was already a prototype for the external function, and if that
82/// prototype doesn't match the arguments we expect to pass in.
83template <class ArgIt>
84static CallInst *ReplaceCallWith(const char *NewFn, CallInst *CI,
Chris Lattnerb76efb72007-01-07 08:12:01 +000085 ArgIt ArgBegin, ArgIt ArgEnd,
86 const Type *RetTy, Constant *&FCache) {
Chris Lattner588e72d2004-02-15 22:16:39 +000087 if (!FCache) {
88 // If we haven't already looked up this function, check to see if the
89 // program already contains a function with this name.
90 Module *M = CI->getParent()->getParent()->getParent();
Chris Lattnerb76efb72007-01-07 08:12:01 +000091 // Get or insert the definition now.
92 std::vector<const Type *> ParamTys;
93 for (ArgIt I = ArgBegin; I != ArgEnd; ++I)
94 ParamTys.push_back((*I)->getType());
95 FCache = M->getOrInsertFunction(NewFn,
96 FunctionType::get(RetTy, ParamTys, false));
Chris Lattner588e72d2004-02-15 22:16:39 +000097 }
Chris Lattner588e72d2004-02-15 22:16:39 +000098
David Greene52eec542007-08-01 03:43:44 +000099 SmallVector<Value *, 8> Args(ArgBegin, ArgEnd);
Gabor Greif051a9502008-04-06 20:25:17 +0000100 CallInst *NewCI = CallInst::Create(FCache, Args.begin(), Args.end(),
101 CI->getName(), CI);
Chris Lattnerb76efb72007-01-07 08:12:01 +0000102 if (!CI->use_empty())
103 CI->replaceAllUsesWith(NewCI);
Chris Lattner02348ca2004-06-11 02:54:02 +0000104 return NewCI;
Chris Lattner588e72d2004-02-15 22:16:39 +0000105}
106
Chris Lattnerb71fd782006-11-15 18:00:10 +0000107void IntrinsicLowering::AddPrototypes(Module &M) {
Chris Lattner0979ca72004-05-09 04:29:57 +0000108 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
Reid Spencer5cbf9852007-01-30 20:08:39 +0000109 if (I->isDeclaration() && !I->use_empty())
Chris Lattner0979ca72004-05-09 04:29:57 +0000110 switch (I->getIntrinsicID()) {
111 default: break;
112 case Intrinsic::setjmp:
Chris Lattner1f243e92005-05-08 19:46:29 +0000113 EnsureFunctionExists(M, "setjmp", I->arg_begin(), I->arg_end(),
Reid Spencer47857812006-12-31 05:55:36 +0000114 Type::Int32Ty);
Chris Lattner0979ca72004-05-09 04:29:57 +0000115 break;
116 case Intrinsic::longjmp:
Chris Lattner1f243e92005-05-08 19:46:29 +0000117 EnsureFunctionExists(M, "longjmp", I->arg_begin(), I->arg_end(),
118 Type::VoidTy);
Chris Lattner0979ca72004-05-09 04:29:57 +0000119 break;
120 case Intrinsic::siglongjmp:
Chris Lattner1f243e92005-05-08 19:46:29 +0000121 EnsureFunctionExists(M, "abort", I->arg_end(), I->arg_end(),
122 Type::VoidTy);
Chris Lattner0979ca72004-05-09 04:29:57 +0000123 break;
Chris Lattner824b9582008-11-21 16:42:48 +0000124 case Intrinsic::memcpy:
Christopher Lamb43ad6b32007-12-17 01:12:55 +0000125 M.getOrInsertFunction("memcpy", PointerType::getUnqual(Type::Int8Ty),
126 PointerType::getUnqual(Type::Int8Ty),
127 PointerType::getUnqual(Type::Int8Ty),
Reid Spencer6addf2c2007-01-29 17:42:06 +0000128 TD.getIntPtrType(), (Type *)0);
Chris Lattner0979ca72004-05-09 04:29:57 +0000129 break;
Chris Lattner824b9582008-11-21 16:42:48 +0000130 case Intrinsic::memmove:
Christopher Lamb43ad6b32007-12-17 01:12:55 +0000131 M.getOrInsertFunction("memmove", PointerType::getUnqual(Type::Int8Ty),
132 PointerType::getUnqual(Type::Int8Ty),
133 PointerType::getUnqual(Type::Int8Ty),
Reid Spencer6addf2c2007-01-29 17:42:06 +0000134 TD.getIntPtrType(), (Type *)0);
Chris Lattner0979ca72004-05-09 04:29:57 +0000135 break;
Chris Lattner824b9582008-11-21 16:42:48 +0000136 case Intrinsic::memset:
Christopher Lamb43ad6b32007-12-17 01:12:55 +0000137 M.getOrInsertFunction("memset", PointerType::getUnqual(Type::Int8Ty),
138 PointerType::getUnqual(Type::Int8Ty),
139 Type::Int32Ty,
Reid Spencer6addf2c2007-01-29 17:42:06 +0000140 TD.getIntPtrType(), (Type *)0);
Chris Lattner0979ca72004-05-09 04:29:57 +0000141 break;
Dale Johannesen9ab7fb32007-10-02 17:43:59 +0000142 case Intrinsic::sqrt:
Dale Johannesenc4342ea2008-09-22 19:51:58 +0000143 EnsureFPIntrinsicsExist(M, I, "sqrtf", "sqrt", "sqrtl");
Chris Lattnerb42a9ff2005-04-30 04:07:50 +0000144 break;
Dan Gohmanc4c96602007-10-15 22:07:31 +0000145 case Intrinsic::sin:
Dale Johannesenc4342ea2008-09-22 19:51:58 +0000146 EnsureFPIntrinsicsExist(M, I, "sinf", "sin", "sinl");
Dan Gohmanc4c96602007-10-15 22:07:31 +0000147 break;
148 case Intrinsic::cos:
Dale Johannesenc4342ea2008-09-22 19:51:58 +0000149 EnsureFPIntrinsicsExist(M, I, "cosf", "cos", "cosl");
Dan Gohmanc4c96602007-10-15 22:07:31 +0000150 break;
151 case Intrinsic::pow:
Dale Johannesenc4342ea2008-09-22 19:51:58 +0000152 EnsureFPIntrinsicsExist(M, I, "powf", "pow", "powl");
Dan Gohmanc4c96602007-10-15 22:07:31 +0000153 break;
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000154 case Intrinsic::log:
Dale Johannesenc4342ea2008-09-22 19:51:58 +0000155 EnsureFPIntrinsicsExist(M, I, "logf", "log", "logl");
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000156 break;
157 case Intrinsic::log2:
Dale Johannesenc4342ea2008-09-22 19:51:58 +0000158 EnsureFPIntrinsicsExist(M, I, "log2f", "log2", "log2l");
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000159 break;
160 case Intrinsic::log10:
Dale Johannesenc4342ea2008-09-22 19:51:58 +0000161 EnsureFPIntrinsicsExist(M, I, "log10f", "log10", "log10l");
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000162 break;
163 case Intrinsic::exp:
Dale Johannesenc4342ea2008-09-22 19:51:58 +0000164 EnsureFPIntrinsicsExist(M, I, "expf", "exp", "expl");
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000165 break;
166 case Intrinsic::exp2:
Dale Johannesenc4342ea2008-09-22 19:51:58 +0000167 EnsureFPIntrinsicsExist(M, I, "exp2f", "exp2", "exp2l");
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000168 break;
Chris Lattner0979ca72004-05-09 04:29:57 +0000169 }
Chris Lattner0979ca72004-05-09 04:29:57 +0000170}
Chris Lattner588e72d2004-02-15 22:16:39 +0000171
Nate Begemane5981812006-01-16 07:57:00 +0000172/// LowerBSWAP - Emit the code to lower bswap of V before the specified
173/// instruction IP.
174static Value *LowerBSWAP(Value *V, Instruction *IP) {
Chris Lattner42a75512007-01-15 02:27:26 +0000175 assert(V->getType()->isInteger() && "Can't bswap a non-integer type!");
Nate Begemane5981812006-01-16 07:57:00 +0000176
Nate Begemane5981812006-01-16 07:57:00 +0000177 unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
178
179 switch(BitSize) {
180 default: assert(0 && "Unhandled type size of value to byteswap!");
181 case 16: {
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000182 Value *Tmp1 = BinaryOperator::CreateShl(V,
Reid Spencer832254e2007-02-02 02:16:23 +0000183 ConstantInt::get(V->getType(),8),"bswap.2",IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000184 Value *Tmp2 = BinaryOperator::CreateLShr(V,
Reid Spencer832254e2007-02-02 02:16:23 +0000185 ConstantInt::get(V->getType(),8),"bswap.1",IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000186 V = BinaryOperator::CreateOr(Tmp1, Tmp2, "bswap.i16", IP);
Nate Begemane5981812006-01-16 07:57:00 +0000187 break;
188 }
189 case 32: {
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000190 Value *Tmp4 = BinaryOperator::CreateShl(V,
Reid Spencer832254e2007-02-02 02:16:23 +0000191 ConstantInt::get(V->getType(),24),"bswap.4", IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000192 Value *Tmp3 = BinaryOperator::CreateShl(V,
Reid Spencer832254e2007-02-02 02:16:23 +0000193 ConstantInt::get(V->getType(),8),"bswap.3",IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000194 Value *Tmp2 = BinaryOperator::CreateLShr(V,
Reid Spencer832254e2007-02-02 02:16:23 +0000195 ConstantInt::get(V->getType(),8),"bswap.2",IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000196 Value *Tmp1 = BinaryOperator::CreateLShr(V,
Reid Spencer832254e2007-02-02 02:16:23 +0000197 ConstantInt::get(V->getType(),24),"bswap.1", IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000198 Tmp3 = BinaryOperator::CreateAnd(Tmp3,
Reid Spencer47857812006-12-31 05:55:36 +0000199 ConstantInt::get(Type::Int32Ty, 0xFF0000),
Nate Begemane5981812006-01-16 07:57:00 +0000200 "bswap.and3", IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000201 Tmp2 = BinaryOperator::CreateAnd(Tmp2,
Reid Spencer47857812006-12-31 05:55:36 +0000202 ConstantInt::get(Type::Int32Ty, 0xFF00),
Nate Begemane5981812006-01-16 07:57:00 +0000203 "bswap.and2", IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000204 Tmp4 = BinaryOperator::CreateOr(Tmp4, Tmp3, "bswap.or1", IP);
205 Tmp2 = BinaryOperator::CreateOr(Tmp2, Tmp1, "bswap.or2", IP);
206 V = BinaryOperator::CreateOr(Tmp4, Tmp2, "bswap.i32", IP);
Nate Begemane5981812006-01-16 07:57:00 +0000207 break;
208 }
209 case 64: {
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000210 Value *Tmp8 = BinaryOperator::CreateShl(V,
Reid Spencer832254e2007-02-02 02:16:23 +0000211 ConstantInt::get(V->getType(),56),"bswap.8", IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000212 Value *Tmp7 = BinaryOperator::CreateShl(V,
Reid Spencer832254e2007-02-02 02:16:23 +0000213 ConstantInt::get(V->getType(),40),"bswap.7", IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000214 Value *Tmp6 = BinaryOperator::CreateShl(V,
Reid Spencer832254e2007-02-02 02:16:23 +0000215 ConstantInt::get(V->getType(),24),"bswap.6", IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000216 Value *Tmp5 = BinaryOperator::CreateShl(V,
Reid Spencer832254e2007-02-02 02:16:23 +0000217 ConstantInt::get(V->getType(),8),"bswap.5", IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000218 Value* Tmp4 = BinaryOperator::CreateLShr(V,
Reid Spencer832254e2007-02-02 02:16:23 +0000219 ConstantInt::get(V->getType(),8),"bswap.4", IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000220 Value* Tmp3 = BinaryOperator::CreateLShr(V,
Reid Spencer832254e2007-02-02 02:16:23 +0000221 ConstantInt::get(V->getType(),24),"bswap.3", IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000222 Value* Tmp2 = BinaryOperator::CreateLShr(V,
Reid Spencer832254e2007-02-02 02:16:23 +0000223 ConstantInt::get(V->getType(),40),"bswap.2", IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000224 Value* Tmp1 = BinaryOperator::CreateLShr(V,
Reid Spencer832254e2007-02-02 02:16:23 +0000225 ConstantInt::get(V->getType(),56),"bswap.1", IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000226 Tmp7 = BinaryOperator::CreateAnd(Tmp7,
Reid Spencer47857812006-12-31 05:55:36 +0000227 ConstantInt::get(Type::Int64Ty,
Reid Spencerb83eb642006-10-20 07:07:24 +0000228 0xFF000000000000ULL),
229 "bswap.and7", IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000230 Tmp6 = BinaryOperator::CreateAnd(Tmp6,
Reid Spencer47857812006-12-31 05:55:36 +0000231 ConstantInt::get(Type::Int64Ty, 0xFF0000000000ULL),
Reid Spencerb83eb642006-10-20 07:07:24 +0000232 "bswap.and6", IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000233 Tmp5 = BinaryOperator::CreateAnd(Tmp5,
Reid Spencer47857812006-12-31 05:55:36 +0000234 ConstantInt::get(Type::Int64Ty, 0xFF00000000ULL),
Reid Spencerb83eb642006-10-20 07:07:24 +0000235 "bswap.and5", IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000236 Tmp4 = BinaryOperator::CreateAnd(Tmp4,
Reid Spencer47857812006-12-31 05:55:36 +0000237 ConstantInt::get(Type::Int64Ty, 0xFF000000ULL),
Reid Spencerb83eb642006-10-20 07:07:24 +0000238 "bswap.and4", IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000239 Tmp3 = BinaryOperator::CreateAnd(Tmp3,
Reid Spencer47857812006-12-31 05:55:36 +0000240 ConstantInt::get(Type::Int64Ty, 0xFF0000ULL),
Reid Spencerb83eb642006-10-20 07:07:24 +0000241 "bswap.and3", IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000242 Tmp2 = BinaryOperator::CreateAnd(Tmp2,
Reid Spencer47857812006-12-31 05:55:36 +0000243 ConstantInt::get(Type::Int64Ty, 0xFF00ULL),
Reid Spencerb83eb642006-10-20 07:07:24 +0000244 "bswap.and2", IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000245 Tmp8 = BinaryOperator::CreateOr(Tmp8, Tmp7, "bswap.or1", IP);
246 Tmp6 = BinaryOperator::CreateOr(Tmp6, Tmp5, "bswap.or2", IP);
247 Tmp4 = BinaryOperator::CreateOr(Tmp4, Tmp3, "bswap.or3", IP);
248 Tmp2 = BinaryOperator::CreateOr(Tmp2, Tmp1, "bswap.or4", IP);
249 Tmp8 = BinaryOperator::CreateOr(Tmp8, Tmp6, "bswap.or5", IP);
250 Tmp4 = BinaryOperator::CreateOr(Tmp4, Tmp2, "bswap.or6", IP);
251 V = BinaryOperator::CreateOr(Tmp8, Tmp4, "bswap.i64", IP);
Nate Begemane5981812006-01-16 07:57:00 +0000252 break;
253 }
254 }
Nate Begemane5981812006-01-16 07:57:00 +0000255 return V;
256}
257
Chris Lattner86f3e0c2005-05-11 19:42:05 +0000258/// LowerCTPOP - Emit the code to lower ctpop of V before the specified
Nate Begemane5981812006-01-16 07:57:00 +0000259/// instruction IP.
Chris Lattner86f3e0c2005-05-11 19:42:05 +0000260static Value *LowerCTPOP(Value *V, Instruction *IP) {
Chris Lattner42a75512007-01-15 02:27:26 +0000261 assert(V->getType()->isInteger() && "Can't ctpop a non-integer type!");
Chris Lattner86f3e0c2005-05-11 19:42:05 +0000262
263 static const uint64_t MaskValues[6] = {
264 0x5555555555555555ULL, 0x3333333333333333ULL,
265 0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL,
266 0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL
267 };
268
Chris Lattner98cf45b2005-05-11 20:24:12 +0000269 unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
Zhou Sheng02031c02007-06-02 04:10:33 +0000270 unsigned WordSize = (BitSize + 63) / 64;
271 Value *Count = ConstantInt::get(V->getType(), 0);
Reid Spencer3822ff52006-11-08 06:47:33 +0000272
Zhou Sheng02031c02007-06-02 04:10:33 +0000273 for (unsigned n = 0; n < WordSize; ++n) {
274 Value *PartValue = V;
275 for (unsigned i = 1, ct = 0; i < (BitSize>64 ? 64 : BitSize);
276 i <<= 1, ++ct) {
277 Value *MaskCst = ConstantInt::get(V->getType(), MaskValues[ct]);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000278 Value *LHS = BinaryOperator::CreateAnd(
Zhou Sheng02031c02007-06-02 04:10:33 +0000279 PartValue, MaskCst, "cppop.and1", IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000280 Value *VShift = BinaryOperator::CreateLShr(PartValue,
Zhou Sheng02031c02007-06-02 04:10:33 +0000281 ConstantInt::get(V->getType(), i), "ctpop.sh", IP);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000282 Value *RHS = BinaryOperator::CreateAnd(VShift, MaskCst, "cppop.and2", IP);
283 PartValue = BinaryOperator::CreateAdd(LHS, RHS, "ctpop.step", IP);
Zhou Sheng02031c02007-06-02 04:10:33 +0000284 }
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000285 Count = BinaryOperator::CreateAdd(PartValue, Count, "ctpop.part", IP);
Zhou Sheng02031c02007-06-02 04:10:33 +0000286 if (BitSize > 64) {
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000287 V = BinaryOperator::CreateLShr(V, ConstantInt::get(V->getType(), 64),
Zhou Sheng02031c02007-06-02 04:10:33 +0000288 "ctpop.part.sh", IP);
289 BitSize -= 64;
290 }
Chris Lattner86f3e0c2005-05-11 19:42:05 +0000291 }
292
Chris Lattner914ce452007-08-06 16:36:18 +0000293 return Count;
Chris Lattner86f3e0c2005-05-11 19:42:05 +0000294}
295
Chris Lattner98cf45b2005-05-11 20:24:12 +0000296/// LowerCTLZ - Emit the code to lower ctlz of V before the specified
Nate Begemane5981812006-01-16 07:57:00 +0000297/// instruction IP.
Chris Lattner98cf45b2005-05-11 20:24:12 +0000298static Value *LowerCTLZ(Value *V, Instruction *IP) {
Chris Lattner98cf45b2005-05-11 20:24:12 +0000299
300 unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
Zhou Sheng02031c02007-06-02 04:10:33 +0000301 for (unsigned i = 1; i < BitSize; i <<= 1) {
Reid Spencer832254e2007-02-02 02:16:23 +0000302 Value *ShVal = ConstantInt::get(V->getType(), i);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000303 ShVal = BinaryOperator::CreateLShr(V, ShVal, "ctlz.sh", IP);
304 V = BinaryOperator::CreateOr(V, ShVal, "ctlz.step", IP);
Chris Lattner98cf45b2005-05-11 20:24:12 +0000305 }
306
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000307 V = BinaryOperator::CreateNot(V, "", IP);
Chris Lattner98cf45b2005-05-11 20:24:12 +0000308 return LowerCTPOP(V, IP);
309}
310
Reid Spencerf75b8742007-04-12 02:48:46 +0000311/// Convert the llvm.part.select.iX.iY intrinsic. This intrinsic takes
312/// three integer arguments. The first argument is the Value from which the
313/// bits will be selected. It may be of any bit width. The second and third
314/// arguments specify a range of bits to select with the second argument
315/// specifying the low bit and the third argument specifying the high bit. Both
316/// must be type i32. The result is the corresponding selected bits from the
317/// Value in the same width as the Value (first argument). If the low bit index
318/// is higher than the high bit index then the inverse selection is done and
319/// the bits are returned in inverse order.
320/// @brief Lowering of llvm.part.select intrinsic.
321static Instruction *LowerPartSelect(CallInst *CI) {
Reid Spenceraddd11d2007-04-04 23:48:25 +0000322 // Make sure we're dealing with a part select intrinsic here
323 Function *F = CI->getCalledFunction();
324 const FunctionType *FT = F->getFunctionType();
325 if (!F->isDeclaration() || !FT->getReturnType()->isInteger() ||
326 FT->getNumParams() != 3 || !FT->getParamType(0)->isInteger() ||
327 !FT->getParamType(1)->isInteger() || !FT->getParamType(2)->isInteger())
328 return CI;
329
330 // Get the intrinsic implementation function by converting all the . to _
331 // in the intrinsic's function name and then reconstructing the function
332 // declaration.
333 std::string Name(F->getName());
334 for (unsigned i = 4; i < Name.length(); ++i)
335 if (Name[i] == '.')
336 Name[i] = '_';
337 Module* M = F->getParent();
338 F = cast<Function>(M->getOrInsertFunction(Name, FT));
Duncan Sands667d4b82009-03-07 15:45:40 +0000339 F->setLinkage(GlobalValue::WeakAnyLinkage);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000340
341 // If we haven't defined the impl function yet, do so now
342 if (F->isDeclaration()) {
343
344 // Get the arguments to the function
Reid Spencereeedcb62007-04-12 13:30:14 +0000345 Function::arg_iterator args = F->arg_begin();
346 Value* Val = args++; Val->setName("Val");
347 Value* Lo = args++; Lo->setName("Lo");
Gabor Greif051a9502008-04-06 20:25:17 +0000348 Value* Hi = args++; Hi->setName("High");
Reid Spenceraddd11d2007-04-04 23:48:25 +0000349
Reid Spencereeedcb62007-04-12 13:30:14 +0000350 // We want to select a range of bits here such that [Hi, Lo] is shifted
351 // down to the low bits. However, it is quite possible that Hi is smaller
352 // than Lo in which case the bits have to be reversed.
Reid Spenceraddd11d2007-04-04 23:48:25 +0000353
354 // Create the blocks we will need for the two cases (forward, reverse)
Gabor Greif051a9502008-04-06 20:25:17 +0000355 BasicBlock* CurBB = BasicBlock::Create("entry", F);
356 BasicBlock *RevSize = BasicBlock::Create("revsize", CurBB->getParent());
357 BasicBlock *FwdSize = BasicBlock::Create("fwdsize", CurBB->getParent());
358 BasicBlock *Compute = BasicBlock::Create("compute", CurBB->getParent());
359 BasicBlock *Reverse = BasicBlock::Create("reverse", CurBB->getParent());
360 BasicBlock *RsltBlk = BasicBlock::Create("result", CurBB->getParent());
Reid Spenceraddd11d2007-04-04 23:48:25 +0000361
Reid Spencereeedcb62007-04-12 13:30:14 +0000362 // Cast Hi and Lo to the size of Val so the widths are all the same
363 if (Hi->getType() != Val->getType())
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000364 Hi = CastInst::CreateIntegerCast(Hi, Val->getType(), false,
Reid Spenceraddd11d2007-04-04 23:48:25 +0000365 "tmp", CurBB);
Reid Spencereeedcb62007-04-12 13:30:14 +0000366 if (Lo->getType() != Val->getType())
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000367 Lo = CastInst::CreateIntegerCast(Lo, Val->getType(), false,
Reid Spenceraddd11d2007-04-04 23:48:25 +0000368 "tmp", CurBB);
369
370 // Compute a few things that both cases will need, up front.
371 Constant* Zero = ConstantInt::get(Val->getType(), 0);
372 Constant* One = ConstantInt::get(Val->getType(), 1);
373 Constant* AllOnes = ConstantInt::getAllOnesValue(Val->getType());
374
Reid Spencereeedcb62007-04-12 13:30:14 +0000375 // Compare the Hi and Lo bit positions. This is used to determine
Reid Spenceraddd11d2007-04-04 23:48:25 +0000376 // which case we have (forward or reverse)
Reid Spencereeedcb62007-04-12 13:30:14 +0000377 ICmpInst *Cmp = new ICmpInst(ICmpInst::ICMP_ULT, Hi, Lo, "less",CurBB);
Gabor Greif051a9502008-04-06 20:25:17 +0000378 BranchInst::Create(RevSize, FwdSize, Cmp, CurBB);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000379
380 // First, copmute the number of bits in the forward case.
381 Instruction* FBitSize =
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000382 BinaryOperator::CreateSub(Hi, Lo,"fbits", FwdSize);
Gabor Greif051a9502008-04-06 20:25:17 +0000383 BranchInst::Create(Compute, FwdSize);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000384
385 // Second, compute the number of bits in the reverse case.
386 Instruction* RBitSize =
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000387 BinaryOperator::CreateSub(Lo, Hi, "rbits", RevSize);
Gabor Greif051a9502008-04-06 20:25:17 +0000388 BranchInst::Create(Compute, RevSize);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000389
390 // Now, compute the bit range. Start by getting the bitsize and the shift
Reid Spencereeedcb62007-04-12 13:30:14 +0000391 // amount (either Hi or Lo) from PHI nodes. Then we compute a mask for
Reid Spenceraddd11d2007-04-04 23:48:25 +0000392 // the number of bits we want in the range. We shift the bits down to the
393 // least significant bits, apply the mask to zero out unwanted high bits,
394 // and we have computed the "forward" result. It may still need to be
395 // reversed.
396
397 // Get the BitSize from one of the two subtractions
Gabor Greif051a9502008-04-06 20:25:17 +0000398 PHINode *BitSize = PHINode::Create(Val->getType(), "bits", Compute);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000399 BitSize->reserveOperandSpace(2);
400 BitSize->addIncoming(FBitSize, FwdSize);
401 BitSize->addIncoming(RBitSize, RevSize);
402
Reid Spencereeedcb62007-04-12 13:30:14 +0000403 // Get the ShiftAmount as the smaller of Hi/Lo
Gabor Greif051a9502008-04-06 20:25:17 +0000404 PHINode *ShiftAmt = PHINode::Create(Val->getType(), "shiftamt", Compute);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000405 ShiftAmt->reserveOperandSpace(2);
Reid Spencereeedcb62007-04-12 13:30:14 +0000406 ShiftAmt->addIncoming(Lo, FwdSize);
407 ShiftAmt->addIncoming(Hi, RevSize);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000408
409 // Increment the bit size
410 Instruction *BitSizePlusOne =
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000411 BinaryOperator::CreateAdd(BitSize, One, "bits", Compute);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000412
413 // Create a Mask to zero out the high order bits.
414 Instruction* Mask =
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000415 BinaryOperator::CreateShl(AllOnes, BitSizePlusOne, "mask", Compute);
416 Mask = BinaryOperator::CreateNot(Mask, "mask", Compute);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000417
418 // Shift the bits down and apply the mask
419 Instruction* FRes =
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000420 BinaryOperator::CreateLShr(Val, ShiftAmt, "fres", Compute);
421 FRes = BinaryOperator::CreateAnd(FRes, Mask, "fres", Compute);
Gabor Greif051a9502008-04-06 20:25:17 +0000422 BranchInst::Create(Reverse, RsltBlk, Cmp, Compute);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000423
424 // In the Reverse block we have the mask already in FRes but we must reverse
425 // it by shifting FRes bits right and putting them in RRes by shifting them
426 // in from left.
427
428 // First set up our loop counters
Gabor Greif051a9502008-04-06 20:25:17 +0000429 PHINode *Count = PHINode::Create(Val->getType(), "count", Reverse);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000430 Count->reserveOperandSpace(2);
431 Count->addIncoming(BitSizePlusOne, Compute);
432
433 // Next, get the value that we are shifting.
Gabor Greif051a9502008-04-06 20:25:17 +0000434 PHINode *BitsToShift = PHINode::Create(Val->getType(), "val", Reverse);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000435 BitsToShift->reserveOperandSpace(2);
436 BitsToShift->addIncoming(FRes, Compute);
437
438 // Finally, get the result of the last computation
Gabor Greif051a9502008-04-06 20:25:17 +0000439 PHINode *RRes = PHINode::Create(Val->getType(), "rres", Reverse);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000440 RRes->reserveOperandSpace(2);
441 RRes->addIncoming(Zero, Compute);
442
443 // Decrement the counter
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000444 Instruction *Decr = BinaryOperator::CreateSub(Count, One, "decr", Reverse);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000445 Count->addIncoming(Decr, Reverse);
446
447 // Compute the Bit that we want to move
448 Instruction *Bit =
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000449 BinaryOperator::CreateAnd(BitsToShift, One, "bit", Reverse);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000450
451 // Compute the new value for next iteration.
452 Instruction *NewVal =
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000453 BinaryOperator::CreateLShr(BitsToShift, One, "rshift", Reverse);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000454 BitsToShift->addIncoming(NewVal, Reverse);
455
456 // Shift the bit into the low bits of the result.
457 Instruction *NewRes =
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000458 BinaryOperator::CreateShl(RRes, One, "lshift", Reverse);
459 NewRes = BinaryOperator::CreateOr(NewRes, Bit, "addbit", Reverse);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000460 RRes->addIncoming(NewRes, Reverse);
461
462 // Terminate loop if we've moved all the bits.
463 ICmpInst *Cond =
464 new ICmpInst(ICmpInst::ICMP_EQ, Decr, Zero, "cond", Reverse);
Gabor Greif051a9502008-04-06 20:25:17 +0000465 BranchInst::Create(RsltBlk, Reverse, Cond, Reverse);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000466
467 // Finally, in the result block, select one of the two results with a PHI
468 // node and return the result;
469 CurBB = RsltBlk;
Gabor Greif051a9502008-04-06 20:25:17 +0000470 PHINode *BitSelect = PHINode::Create(Val->getType(), "part_select", CurBB);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000471 BitSelect->reserveOperandSpace(2);
472 BitSelect->addIncoming(FRes, Compute);
473 BitSelect->addIncoming(NewRes, Reverse);
Gabor Greif051a9502008-04-06 20:25:17 +0000474 ReturnInst::Create(BitSelect, CurBB);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000475 }
476
477 // Return a call to the implementation function
Reid Spencer5156f5b2007-05-12 11:07:40 +0000478 Value *Args[] = {
479 CI->getOperand(1),
480 CI->getOperand(2),
481 CI->getOperand(3)
482 };
Gabor Greif051a9502008-04-06 20:25:17 +0000483 return CallInst::Create(F, Args, array_endof(Args), CI->getName(), CI);
Reid Spenceraddd11d2007-04-04 23:48:25 +0000484}
485
Reid Spencerf75b8742007-04-12 02:48:46 +0000486/// Convert the llvm.part.set.iX.iY.iZ intrinsic. This intrinsic takes
487/// four integer arguments (iAny %Value, iAny %Replacement, i32 %Low, i32 %High)
488/// The first two arguments can be any bit width. The result is the same width
489/// as %Value. The operation replaces bits between %Low and %High with the value
490/// in %Replacement. If %Replacement is not the same width, it is truncated or
491/// zero extended as appropriate to fit the bits being replaced. If %Low is
492/// greater than %High then the inverse set of bits are replaced.
493/// @brief Lowering of llvm.bit.part.set intrinsic.
494static Instruction *LowerPartSet(CallInst *CI) {
495 // Make sure we're dealing with a part select intrinsic here
496 Function *F = CI->getCalledFunction();
497 const FunctionType *FT = F->getFunctionType();
498 if (!F->isDeclaration() || !FT->getReturnType()->isInteger() ||
499 FT->getNumParams() != 4 || !FT->getParamType(0)->isInteger() ||
500 !FT->getParamType(1)->isInteger() || !FT->getParamType(2)->isInteger() ||
501 !FT->getParamType(3)->isInteger())
502 return CI;
503
504 // Get the intrinsic implementation function by converting all the . to _
505 // in the intrinsic's function name and then reconstructing the function
506 // declaration.
507 std::string Name(F->getName());
508 for (unsigned i = 4; i < Name.length(); ++i)
509 if (Name[i] == '.')
510 Name[i] = '_';
511 Module* M = F->getParent();
512 F = cast<Function>(M->getOrInsertFunction(Name, FT));
Duncan Sands667d4b82009-03-07 15:45:40 +0000513 F->setLinkage(GlobalValue::WeakAnyLinkage);
Reid Spencerf75b8742007-04-12 02:48:46 +0000514
515 // If we haven't defined the impl function yet, do so now
516 if (F->isDeclaration()) {
Reid Spencerf75b8742007-04-12 02:48:46 +0000517 // Get the arguments for the function.
518 Function::arg_iterator args = F->arg_begin();
519 Value* Val = args++; Val->setName("Val");
520 Value* Rep = args++; Rep->setName("Rep");
521 Value* Lo = args++; Lo->setName("Lo");
522 Value* Hi = args++; Hi->setName("Hi");
523
524 // Get some types we need
525 const IntegerType* ValTy = cast<IntegerType>(Val->getType());
526 const IntegerType* RepTy = cast<IntegerType>(Rep->getType());
Reid Spencerf75b8742007-04-12 02:48:46 +0000527 uint32_t RepBits = RepTy->getBitWidth();
528
529 // Constant Definitions
530 ConstantInt* RepBitWidth = ConstantInt::get(Type::Int32Ty, RepBits);
531 ConstantInt* RepMask = ConstantInt::getAllOnesValue(RepTy);
532 ConstantInt* ValMask = ConstantInt::getAllOnesValue(ValTy);
Reid Spencer76c94b62007-05-15 02:26:52 +0000533 ConstantInt* One = ConstantInt::get(Type::Int32Ty, 1);
534 ConstantInt* ValOne = ConstantInt::get(ValTy, 1);
535 ConstantInt* Zero = ConstantInt::get(Type::Int32Ty, 0);
536 ConstantInt* ValZero = ConstantInt::get(ValTy, 0);
Reid Spencerf75b8742007-04-12 02:48:46 +0000537
Reid Spencer76c94b62007-05-15 02:26:52 +0000538 // Basic blocks we fill in below.
Gabor Greif051a9502008-04-06 20:25:17 +0000539 BasicBlock* entry = BasicBlock::Create("entry", F, 0);
540 BasicBlock* large = BasicBlock::Create("large", F, 0);
541 BasicBlock* small = BasicBlock::Create("small", F, 0);
542 BasicBlock* reverse = BasicBlock::Create("reverse", F, 0);
543 BasicBlock* result = BasicBlock::Create("result", F, 0);
Reid Spencerf75b8742007-04-12 02:48:46 +0000544
Reid Spencer76c94b62007-05-15 02:26:52 +0000545 // BASIC BLOCK: entry
Reid Spencereeedcb62007-04-12 13:30:14 +0000546 // First, get the number of bits that we're placing as an i32
547 ICmpInst* is_forward =
548 new ICmpInst(ICmpInst::ICMP_ULT, Lo, Hi, "", entry);
Gabor Greif051a9502008-04-06 20:25:17 +0000549 SelectInst* Hi_pn = SelectInst::Create(is_forward, Hi, Lo, "", entry);
550 SelectInst* Lo_pn = SelectInst::Create(is_forward, Lo, Hi, "", entry);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000551 BinaryOperator* NumBits = BinaryOperator::CreateSub(Hi_pn, Lo_pn, "",entry);
552 NumBits = BinaryOperator::CreateAdd(NumBits, One, "", entry);
Reid Spencereeedcb62007-04-12 13:30:14 +0000553 // Now, convert Lo and Hi to ValTy bit width
Jay Foad589b1ef2009-05-11 11:32:25 +0000554 Lo = getZExtOrTrunc(Lo_pn, ValTy, entry);
Reid Spencereeedcb62007-04-12 13:30:14 +0000555 // Determine if the replacement bits are larger than the number of bits we
556 // are replacing and deal with it.
Reid Spencerf75b8742007-04-12 02:48:46 +0000557 ICmpInst* is_large =
558 new ICmpInst(ICmpInst::ICMP_ULT, NumBits, RepBitWidth, "", entry);
Gabor Greif051a9502008-04-06 20:25:17 +0000559 BranchInst::Create(large, small, is_large, entry);
Reid Spencerf75b8742007-04-12 02:48:46 +0000560
Reid Spencer76c94b62007-05-15 02:26:52 +0000561 // BASIC BLOCK: large
Reid Spencer9a9203b2007-04-16 22:21:14 +0000562 Instruction* MaskBits =
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000563 BinaryOperator::CreateSub(RepBitWidth, NumBits, "", large);
564 MaskBits = CastInst::CreateIntegerCast(MaskBits, RepMask->getType(),
Reid Spencer9a9203b2007-04-16 22:21:14 +0000565 false, "", large);
Reid Spencerf75b8742007-04-12 02:48:46 +0000566 BinaryOperator* Mask1 =
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000567 BinaryOperator::CreateLShr(RepMask, MaskBits, "", large);
568 BinaryOperator* Rep2 = BinaryOperator::CreateAnd(Mask1, Rep, "", large);
Gabor Greif051a9502008-04-06 20:25:17 +0000569 BranchInst::Create(small, large);
Reid Spencerf75b8742007-04-12 02:48:46 +0000570
Reid Spencer76c94b62007-05-15 02:26:52 +0000571 // BASIC BLOCK: small
Gabor Greif051a9502008-04-06 20:25:17 +0000572 PHINode* Rep3 = PHINode::Create(RepTy, "", small);
Reid Spencerf75b8742007-04-12 02:48:46 +0000573 Rep3->reserveOperandSpace(2);
Reid Spencereeedcb62007-04-12 13:30:14 +0000574 Rep3->addIncoming(Rep2, large);
Reid Spencerf75b8742007-04-12 02:48:46 +0000575 Rep3->addIncoming(Rep, entry);
Jay Foad589b1ef2009-05-11 11:32:25 +0000576 Value* Rep4 = getZExtOrTrunc(Rep3, ValTy, small);
Gabor Greif051a9502008-04-06 20:25:17 +0000577 BranchInst::Create(result, reverse, is_forward, small);
Reid Spencerf75b8742007-04-12 02:48:46 +0000578
Reid Spencer76c94b62007-05-15 02:26:52 +0000579 // BASIC BLOCK: reverse (reverses the bits of the replacement)
580 // Set up our loop counter as a PHI so we can decrement on each iteration.
581 // We will loop for the number of bits in the replacement value.
Gabor Greif051a9502008-04-06 20:25:17 +0000582 PHINode *Count = PHINode::Create(Type::Int32Ty, "count", reverse);
Reid Spencer76c94b62007-05-15 02:26:52 +0000583 Count->reserveOperandSpace(2);
584 Count->addIncoming(NumBits, small);
Reid Spencerf75b8742007-04-12 02:48:46 +0000585
Reid Spencer76c94b62007-05-15 02:26:52 +0000586 // Get the value that we are shifting bits out of as a PHI because
587 // we'll change this with each iteration.
Gabor Greif051a9502008-04-06 20:25:17 +0000588 PHINode *BitsToShift = PHINode::Create(Val->getType(), "val", reverse);
Reid Spencer76c94b62007-05-15 02:26:52 +0000589 BitsToShift->reserveOperandSpace(2);
590 BitsToShift->addIncoming(Rep4, small);
591
592 // Get the result of the last computation or zero on first iteration
Gabor Greif051a9502008-04-06 20:25:17 +0000593 PHINode *RRes = PHINode::Create(Val->getType(), "rres", reverse);
Reid Spencer76c94b62007-05-15 02:26:52 +0000594 RRes->reserveOperandSpace(2);
595 RRes->addIncoming(ValZero, small);
596
597 // Decrement the loop counter by one
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000598 Instruction *Decr = BinaryOperator::CreateSub(Count, One, "", reverse);
Reid Spencer76c94b62007-05-15 02:26:52 +0000599 Count->addIncoming(Decr, reverse);
600
601 // Get the bit that we want to move into the result
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000602 Value *Bit = BinaryOperator::CreateAnd(BitsToShift, ValOne, "", reverse);
Reid Spencer76c94b62007-05-15 02:26:52 +0000603
604 // Compute the new value of the bits to shift for the next iteration.
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000605 Value *NewVal = BinaryOperator::CreateLShr(BitsToShift, ValOne,"", reverse);
Reid Spencer76c94b62007-05-15 02:26:52 +0000606 BitsToShift->addIncoming(NewVal, reverse);
607
608 // Shift the bit we extracted into the low bit of the result.
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000609 Instruction *NewRes = BinaryOperator::CreateShl(RRes, ValOne, "", reverse);
610 NewRes = BinaryOperator::CreateOr(NewRes, Bit, "", reverse);
Reid Spencer76c94b62007-05-15 02:26:52 +0000611 RRes->addIncoming(NewRes, reverse);
612
613 // Terminate loop if we've moved all the bits.
614 ICmpInst *Cond = new ICmpInst(ICmpInst::ICMP_EQ, Decr, Zero, "", reverse);
Gabor Greif051a9502008-04-06 20:25:17 +0000615 BranchInst::Create(result, reverse, Cond, reverse);
Reid Spencer76c94b62007-05-15 02:26:52 +0000616
617 // BASIC BLOCK: result
Gabor Greif051a9502008-04-06 20:25:17 +0000618 PHINode *Rplcmnt = PHINode::Create(Val->getType(), "", result);
Reid Spencer76c94b62007-05-15 02:26:52 +0000619 Rplcmnt->reserveOperandSpace(2);
620 Rplcmnt->addIncoming(NewRes, reverse);
621 Rplcmnt->addIncoming(Rep4, small);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000622 Value* t0 = CastInst::CreateIntegerCast(NumBits,ValTy,false,"",result);
623 Value* t1 = BinaryOperator::CreateShl(ValMask, Lo, "", result);
624 Value* t2 = BinaryOperator::CreateNot(t1, "", result);
625 Value* t3 = BinaryOperator::CreateShl(t1, t0, "", result);
626 Value* t4 = BinaryOperator::CreateOr(t2, t3, "", result);
627 Value* t5 = BinaryOperator::CreateAnd(t4, Val, "", result);
628 Value* t6 = BinaryOperator::CreateShl(Rplcmnt, Lo, "", result);
629 Value* Rslt = BinaryOperator::CreateOr(t5, t6, "part_set", result);
Gabor Greif051a9502008-04-06 20:25:17 +0000630 ReturnInst::Create(Rslt, result);
Reid Spencerf75b8742007-04-12 02:48:46 +0000631 }
632
633 // Return a call to the implementation function
Reid Spencer5156f5b2007-05-12 11:07:40 +0000634 Value *Args[] = {
635 CI->getOperand(1),
636 CI->getOperand(2),
637 CI->getOperand(3),
638 CI->getOperand(4)
639 };
Gabor Greif051a9502008-04-06 20:25:17 +0000640 return CallInst::Create(F, Args, array_endof(Args), CI->getName(), CI);
Reid Spencerf75b8742007-04-12 02:48:46 +0000641}
642
Dale Johannesenf74185b2008-09-22 20:51:30 +0000643static void ReplaceFPIntrinsicWithCall(CallInst *CI, Constant *FCache,
644 Constant *DCache, Constant *LDCache,
645 const char *Fname, const char *Dname,
646 const char *LDname) {
647 switch (CI->getOperand(1)->getType()->getTypeID()) {
648 default: assert(0 && "Invalid type in intrinsic"); abort();
649 case Type::FloatTyID:
650 ReplaceCallWith(Fname, CI, CI->op_begin()+1, CI->op_end(),
651 Type::FloatTy, FCache);
652 break;
653 case Type::DoubleTyID:
654 ReplaceCallWith(Dname, CI, CI->op_begin()+1, CI->op_end(),
655 Type::DoubleTy, DCache);
656 break;
657 case Type::X86_FP80TyID:
658 case Type::FP128TyID:
659 case Type::PPC_FP128TyID:
660 ReplaceCallWith(LDname, CI, CI->op_begin()+1, CI->op_end(),
661 CI->getOperand(1)->getType(), LDCache);
662 break;
663 }
664}
Reid Spenceraddd11d2007-04-04 23:48:25 +0000665
Chris Lattnerb71fd782006-11-15 18:00:10 +0000666void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
Chris Lattner3b66ecb2003-12-28 08:19:41 +0000667 Function *Callee = CI->getCalledFunction();
668 assert(Callee && "Cannot lower an indirect call!");
Misha Brukmanedf128a2005-04-21 22:36:52 +0000669
Chris Lattner3b66ecb2003-12-28 08:19:41 +0000670 switch (Callee->getIntrinsicID()) {
671 case Intrinsic::not_intrinsic:
Bill Wendlinge8156192006-12-07 01:30:32 +0000672 cerr << "Cannot lower a call to a non-intrinsic function '"
673 << Callee->getName() << "'!\n";
Chris Lattner3b66ecb2003-12-28 08:19:41 +0000674 abort();
675 default:
Bill Wendlinge8156192006-12-07 01:30:32 +0000676 cerr << "Error: Code generator does not support intrinsic function '"
677 << Callee->getName() << "'!\n";
Chris Lattner3b66ecb2003-12-28 08:19:41 +0000678 abort();
679
Chris Lattner588e72d2004-02-15 22:16:39 +0000680 // The setjmp/longjmp intrinsics should only exist in the code if it was
681 // never optimized (ie, right out of the CFE), or if it has been hacked on
682 // by the lowerinvoke pass. In both cases, the right thing to do is to
683 // convert the call to an explicit setjmp or longjmp call.
Chris Lattner9b700f72004-02-15 22:24:51 +0000684 case Intrinsic::setjmp: {
Chris Lattnerb76efb72007-01-07 08:12:01 +0000685 static Constant *SetjmpFCache = 0;
Chris Lattner9b700f72004-02-15 22:24:51 +0000686 Value *V = ReplaceCallWith("setjmp", CI, CI->op_begin()+1, CI->op_end(),
Chris Lattnerb76efb72007-01-07 08:12:01 +0000687 Type::Int32Ty, SetjmpFCache);
Chris Lattner3b66ecb2003-12-28 08:19:41 +0000688 if (CI->getType() != Type::VoidTy)
Chris Lattner9b700f72004-02-15 22:24:51 +0000689 CI->replaceAllUsesWith(V);
Chris Lattner3b66ecb2003-12-28 08:19:41 +0000690 break;
Chris Lattner9b700f72004-02-15 22:24:51 +0000691 }
Misha Brukmanedf128a2005-04-21 22:36:52 +0000692 case Intrinsic::sigsetjmp:
Chris Lattner9b700f72004-02-15 22:24:51 +0000693 if (CI->getType() != Type::VoidTy)
694 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
695 break;
Chris Lattner3b66ecb2003-12-28 08:19:41 +0000696
Chris Lattnerf0a3e6c2004-06-05 01:05:19 +0000697 case Intrinsic::longjmp: {
Chris Lattnerb76efb72007-01-07 08:12:01 +0000698 static Constant *LongjmpFCache = 0;
Chris Lattner9b700f72004-02-15 22:24:51 +0000699 ReplaceCallWith("longjmp", CI, CI->op_begin()+1, CI->op_end(),
Chris Lattnerb76efb72007-01-07 08:12:01 +0000700 Type::VoidTy, LongjmpFCache);
Chris Lattner9b700f72004-02-15 22:24:51 +0000701 break;
Chris Lattnerf0a3e6c2004-06-05 01:05:19 +0000702 }
Chris Lattner9b700f72004-02-15 22:24:51 +0000703
Chris Lattnerf0a3e6c2004-06-05 01:05:19 +0000704 case Intrinsic::siglongjmp: {
Chris Lattner3b66ecb2003-12-28 08:19:41 +0000705 // Insert the call to abort
Chris Lattnerb76efb72007-01-07 08:12:01 +0000706 static Constant *AbortFCache = 0;
Reid Spencer3da59db2006-11-27 01:05:10 +0000707 ReplaceCallWith("abort", CI, CI->op_end(), CI->op_end(),
Chris Lattnerb76efb72007-01-07 08:12:01 +0000708 Type::VoidTy, AbortFCache);
Chris Lattner3b66ecb2003-12-28 08:19:41 +0000709 break;
Chris Lattnerf0a3e6c2004-06-05 01:05:19 +0000710 }
Reid Spencere9391fd2007-04-01 07:35:23 +0000711 case Intrinsic::ctpop:
Reid Spencer0b118202006-01-16 21:12:35 +0000712 CI->replaceAllUsesWith(LowerCTPOP(CI->getOperand(1), CI));
713 break;
714
Reid Spencere9391fd2007-04-01 07:35:23 +0000715 case Intrinsic::bswap:
Nate Begemane5981812006-01-16 07:57:00 +0000716 CI->replaceAllUsesWith(LowerBSWAP(CI->getOperand(1), CI));
717 break;
718
Reid Spencere9391fd2007-04-01 07:35:23 +0000719 case Intrinsic::ctlz:
Chris Lattner98cf45b2005-05-11 20:24:12 +0000720 CI->replaceAllUsesWith(LowerCTLZ(CI->getOperand(1), CI));
Andrew Lenharth691ef2b2005-05-03 17:19:30 +0000721 break;
Nate Begemane5981812006-01-16 07:57:00 +0000722
Reid Spencere9391fd2007-04-01 07:35:23 +0000723 case Intrinsic::cttz: {
Chris Lattnera8011722005-05-11 20:02:14 +0000724 // cttz(x) -> ctpop(~X & (X-1))
Andrew Lenharth691ef2b2005-05-03 17:19:30 +0000725 Value *Src = CI->getOperand(1);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000726 Value *NotSrc = BinaryOperator::CreateNot(Src, Src->getName()+".not", CI);
Gabor Greif051a9502008-04-06 20:25:17 +0000727 Value *SrcM1 = ConstantInt::get(Src->getType(), 1);
Gabor Greif7cbd8a32008-05-16 19:29:10 +0000728 SrcM1 = BinaryOperator::CreateSub(Src, SrcM1, "", CI);
729 Src = LowerCTPOP(BinaryOperator::CreateAnd(NotSrc, SrcM1, "", CI), CI);
Andrew Lenharth691ef2b2005-05-03 17:19:30 +0000730 CI->replaceAllUsesWith(Src);
731 break;
732 }
Chris Lattner77b13302004-01-05 05:36:30 +0000733
Chris Lattnerc6eb6d72007-04-10 03:20:39 +0000734 case Intrinsic::part_select:
Reid Spencerf75b8742007-04-12 02:48:46 +0000735 CI->replaceAllUsesWith(LowerPartSelect(CI));
736 break;
737
738 case Intrinsic::part_set:
739 CI->replaceAllUsesWith(LowerPartSet(CI));
Reid Spenceraddd11d2007-04-04 23:48:25 +0000740 break;
741
Chris Lattner0c067bc2006-01-13 02:22:08 +0000742 case Intrinsic::stacksave:
743 case Intrinsic::stackrestore: {
744 static bool Warned = false;
745 if (!Warned)
Bill Wendlinge8156192006-12-07 01:30:32 +0000746 cerr << "WARNING: this target does not support the llvm.stack"
747 << (Callee->getIntrinsicID() == Intrinsic::stacksave ?
748 "save" : "restore") << " intrinsic.\n";
Chris Lattner0c067bc2006-01-13 02:22:08 +0000749 Warned = true;
750 if (Callee->getIntrinsicID() == Intrinsic::stacksave)
751 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
752 break;
753 }
754
Chris Lattnercf899082004-02-14 02:47:17 +0000755 case Intrinsic::returnaddress:
756 case Intrinsic::frameaddress:
Bill Wendlinge8156192006-12-07 01:30:32 +0000757 cerr << "WARNING: this target does not support the llvm."
758 << (Callee->getIntrinsicID() == Intrinsic::returnaddress ?
759 "return" : "frame") << "address intrinsic.\n";
Chris Lattnercf899082004-02-14 02:47:17 +0000760 CI->replaceAllUsesWith(ConstantPointerNull::get(
761 cast<PointerType>(CI->getType())));
762 break;
763
Chris Lattner0942b7c2005-02-28 19:27:23 +0000764 case Intrinsic::prefetch:
765 break; // Simply strip out prefetches on unsupported architectures
766
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +0000767 case Intrinsic::pcmarker:
768 break; // Simply strip out pcmarker on unsupported architectures
Andrew Lenharth51b8d542005-11-11 16:47:30 +0000769 case Intrinsic::readcyclecounter: {
Bill Wendlinge8156192006-12-07 01:30:32 +0000770 cerr << "WARNING: this target does not support the llvm.readcyclecoun"
771 << "ter intrinsic. It is being lowered to a constant 0\n";
Reid Spencer47857812006-12-31 05:55:36 +0000772 CI->replaceAllUsesWith(ConstantInt::get(Type::Int64Ty, 0));
Andrew Lenharth51b8d542005-11-11 16:47:30 +0000773 break;
774 }
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +0000775
Chris Lattner77b13302004-01-05 05:36:30 +0000776 case Intrinsic::dbg_stoppoint:
777 case Intrinsic::dbg_region_start:
778 case Intrinsic::dbg_region_end:
779 case Intrinsic::dbg_func_start:
Jim Laskey43970fe2006-03-23 18:06:46 +0000780 case Intrinsic::dbg_declare:
Duncan Sandsf664e412007-07-06 14:46:23 +0000781 break; // Simply strip out debugging intrinsics
782
Jim Laskeyb180aa12007-02-21 22:53:45 +0000783 case Intrinsic::eh_exception:
Anton Korobeynikov8806c7b2007-09-07 11:39:35 +0000784 case Intrinsic::eh_selector_i32:
785 case Intrinsic::eh_selector_i64:
Duncan Sandsf664e412007-07-06 14:46:23 +0000786 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
787 break;
788
Anton Korobeynikov8806c7b2007-09-07 11:39:35 +0000789 case Intrinsic::eh_typeid_for_i32:
790 case Intrinsic::eh_typeid_for_i64:
Duncan Sandsf664e412007-07-06 14:46:23 +0000791 // Return something different to eh_selector.
792 CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1));
793 break;
Chris Lattner5fe51cc2004-02-12 17:01:09 +0000794
Tanya Lattner24e5aad2007-06-15 22:26:58 +0000795 case Intrinsic::var_annotation:
796 break; // Strip out annotate intrinsic
797
Chris Lattner824b9582008-11-21 16:42:48 +0000798 case Intrinsic::memcpy: {
Chris Lattnerb76efb72007-01-07 08:12:01 +0000799 static Constant *MemcpyFCache = 0;
Jay Foad589b1ef2009-05-11 11:32:25 +0000800 const IntegerType *IntPtr = TD.getIntPtrType();
801 Value *Size = getZExtOrTrunc(CI->getOperand(3), IntPtr, CI);
Chris Lattnerc67da0c2007-02-06 19:06:38 +0000802 Value *Ops[3];
803 Ops[0] = CI->getOperand(1);
804 Ops[1] = CI->getOperand(2);
805 Ops[2] = Size;
806 ReplaceCallWith("memcpy", CI, Ops, Ops+3, CI->getOperand(1)->getType(),
807 MemcpyFCache);
Reid Spencer3da59db2006-11-27 01:05:10 +0000808 break;
809 }
Chris Lattner824b9582008-11-21 16:42:48 +0000810 case Intrinsic::memmove: {
Chris Lattnerb76efb72007-01-07 08:12:01 +0000811 static Constant *MemmoveFCache = 0;
Jay Foad589b1ef2009-05-11 11:32:25 +0000812 const IntegerType *IntPtr = TD.getIntPtrType();
813 Value *Size = getZExtOrTrunc(CI->getOperand(3), IntPtr, CI);
Chris Lattnerc67da0c2007-02-06 19:06:38 +0000814 Value *Ops[3];
815 Ops[0] = CI->getOperand(1);
816 Ops[1] = CI->getOperand(2);
817 Ops[2] = Size;
818 ReplaceCallWith("memmove", CI, Ops, Ops+3, CI->getOperand(1)->getType(),
819 MemmoveFCache);
Chris Lattner2751e762004-02-12 18:11:20 +0000820 break;
Chris Lattnerf0a3e6c2004-06-05 01:05:19 +0000821 }
Chris Lattner824b9582008-11-21 16:42:48 +0000822 case Intrinsic::memset: {
Chris Lattnerb76efb72007-01-07 08:12:01 +0000823 static Constant *MemsetFCache = 0;
Jay Foad589b1ef2009-05-11 11:32:25 +0000824 const IntegerType *IntPtr = TD.getIntPtrType();
825 Value *Size = getZExtOrTrunc(CI->getOperand(3), IntPtr, CI);
Chris Lattnerc67da0c2007-02-06 19:06:38 +0000826 Value *Ops[3];
827 Ops[0] = CI->getOperand(1);
828 // Extend the amount to i32.
Jay Foad589b1ef2009-05-11 11:32:25 +0000829 Ops[1] = getZExtOrTrunc(CI->getOperand(2), Type::Int32Ty, CI);
Chris Lattnerc67da0c2007-02-06 19:06:38 +0000830 Ops[2] = Size;
831 ReplaceCallWith("memset", CI, Ops, Ops+3, CI->getOperand(1)->getType(),
832 MemsetFCache);
Chris Lattnercf899082004-02-14 02:47:17 +0000833 break;
834 }
Dale Johannesen9ab7fb32007-10-02 17:43:59 +0000835 case Intrinsic::sqrt: {
Chris Lattnerb76efb72007-01-07 08:12:01 +0000836 static Constant *sqrtFCache = 0;
Dale Johannesenf74185b2008-09-22 20:51:30 +0000837 static Constant *sqrtDCache = 0;
Dale Johannesen9ab7fb32007-10-02 17:43:59 +0000838 static Constant *sqrtLDCache = 0;
Dale Johannesenf74185b2008-09-22 20:51:30 +0000839 ReplaceFPIntrinsicWithCall(CI, sqrtFCache, sqrtDCache, sqrtLDCache,
840 "sqrtf", "sqrt", "sqrtl");
Dale Johannesen4292d1c2007-09-28 18:06:58 +0000841 break;
842 }
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000843 case Intrinsic::log: {
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000844 static Constant *logFCache = 0;
Dale Johannesenf74185b2008-09-22 20:51:30 +0000845 static Constant *logDCache = 0;
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000846 static Constant *logLDCache = 0;
Dale Johannesenf74185b2008-09-22 20:51:30 +0000847 ReplaceFPIntrinsicWithCall(CI, logFCache, logDCache, logLDCache,
848 "logf", "log", "logl");
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000849 break;
850 }
851 case Intrinsic::log2: {
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000852 static Constant *log2FCache = 0;
Dale Johannesenf74185b2008-09-22 20:51:30 +0000853 static Constant *log2DCache = 0;
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000854 static Constant *log2LDCache = 0;
Dale Johannesenf74185b2008-09-22 20:51:30 +0000855 ReplaceFPIntrinsicWithCall(CI, log2FCache, log2DCache, log2LDCache,
856 "log2f", "log2", "log2l");
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000857 break;
858 }
859 case Intrinsic::log10: {
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000860 static Constant *log10FCache = 0;
Dale Johannesenf74185b2008-09-22 20:51:30 +0000861 static Constant *log10DCache = 0;
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000862 static Constant *log10LDCache = 0;
Dale Johannesenf74185b2008-09-22 20:51:30 +0000863 ReplaceFPIntrinsicWithCall(CI, log10FCache, log10DCache, log10LDCache,
864 "log10f", "log10", "log10l");
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000865 break;
866 }
867 case Intrinsic::exp: {
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000868 static Constant *expFCache = 0;
Dale Johannesenf74185b2008-09-22 20:51:30 +0000869 static Constant *expDCache = 0;
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000870 static Constant *expLDCache = 0;
Dale Johannesenf74185b2008-09-22 20:51:30 +0000871 ReplaceFPIntrinsicWithCall(CI, expFCache, expDCache, expLDCache,
872 "expf", "exp", "expl");
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000873 break;
874 }
875 case Intrinsic::exp2: {
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000876 static Constant *exp2FCache = 0;
Dale Johannesenf74185b2008-09-22 20:51:30 +0000877 static Constant *exp2DCache = 0;
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000878 static Constant *exp2LDCache = 0;
Dale Johannesenf74185b2008-09-22 20:51:30 +0000879 ReplaceFPIntrinsicWithCall(CI, exp2FCache, exp2DCache, exp2LDCache,
880 "exp2f", "exp2", "exp2l");
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000881 break;
882 }
883 case Intrinsic::pow: {
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000884 static Constant *powFCache = 0;
Dale Johannesenf74185b2008-09-22 20:51:30 +0000885 static Constant *powDCache = 0;
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000886 static Constant *powLDCache = 0;
Dale Johannesenf74185b2008-09-22 20:51:30 +0000887 ReplaceFPIntrinsicWithCall(CI, powFCache, powDCache, powLDCache,
888 "powf", "pow", "powl");
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000889 break;
890 }
Anton Korobeynikov917c2a62007-11-15 23:25:33 +0000891 case Intrinsic::flt_rounds:
892 // Lower to "round to the nearest"
893 if (CI->getType() != Type::VoidTy)
894 CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1));
895 break;
Chris Lattnerf0a3e6c2004-06-05 01:05:19 +0000896 }
Misha Brukmanedf128a2005-04-21 22:36:52 +0000897
Chris Lattner3b66ecb2003-12-28 08:19:41 +0000898 assert(CI->use_empty() &&
899 "Lowering should have eliminated any uses of the intrinsic call!");
Chris Lattner86f3e0c2005-05-11 19:42:05 +0000900 CI->eraseFromParent();
Chris Lattner3b66ecb2003-12-28 08:19:41 +0000901}