For PR950:
[oota-llvm.git] / lib / CodeGen / IntrinsicLowering.cpp
1 //===-- IntrinsicLowering.cpp - Intrinsic Lowering default implementation -===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the IntrinsicLowering class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/CodeGen/IntrinsicLowering.h"
15 #include "llvm/Constants.h"
16 #include "llvm/DerivedTypes.h"
17 #include "llvm/Module.h"
18 #include "llvm/Instructions.h"
19 #include "llvm/Type.h"
20 #include <iostream>
21
22 using namespace llvm;
23
24 template <class ArgIt>
25 static Function *EnsureFunctionExists(Module &M, const char *Name,
26                                       ArgIt ArgBegin, ArgIt ArgEnd,
27                                       const Type *RetTy) {
28   if (Function *F = M.getNamedFunction(Name)) return F;
29   // It doesn't already exist in the program, insert a new definition now.
30   std::vector<const Type *> ParamTys;
31   for (ArgIt I = ArgBegin; I != ArgEnd; ++I)
32     ParamTys.push_back(I->getType());
33   return M.getOrInsertFunction(Name, FunctionType::get(RetTy, ParamTys, false));
34 }
35
36 /// ReplaceCallWith - This function is used when we want to lower an intrinsic
37 /// call to a call of an external function.  This handles hard cases such as
38 /// when there was already a prototype for the external function, and if that
39 /// prototype doesn't match the arguments we expect to pass in.
40 template <class ArgIt>
41 static CallInst *ReplaceCallWith(const char *NewFn, CallInst *CI,
42                                  ArgIt ArgBegin, ArgIt ArgEnd,
43                                  const unsigned *castOpcodes,
44                                  const Type *RetTy, Function *&FCache) {
45   if (!FCache) {
46     // If we haven't already looked up this function, check to see if the
47     // program already contains a function with this name.
48     Module *M = CI->getParent()->getParent()->getParent();
49     FCache = M->getNamedFunction(NewFn);
50     if (!FCache) {
51       // It doesn't already exist in the program, insert a new definition now.
52       std::vector<const Type *> ParamTys;
53       for (ArgIt I = ArgBegin; I != ArgEnd; ++I)
54         ParamTys.push_back((*I)->getType());
55       FCache = M->getOrInsertFunction(NewFn,
56                                      FunctionType::get(RetTy, ParamTys, false));
57     }
58    }
59
60   const FunctionType *FT = FCache->getFunctionType();
61   std::vector<Value*> Operands;
62   unsigned ArgNo = 0;
63   for (ArgIt I = ArgBegin; I != ArgEnd && ArgNo != FT->getNumParams();
64        ++I, ++ArgNo) {
65     Value *Arg = *I;
66     if (Arg->getType() != FT->getParamType(ArgNo))
67       if (castOpcodes[ArgNo])
68         Arg = CastInst::create(Instruction::CastOps(castOpcodes[ArgNo]),
69           Arg, FT->getParamType(ArgNo), Arg->getName(), CI);
70       else
71         Arg = CastInst::createInferredCast(Arg, FT->getParamType(ArgNo), 
72                                            Arg->getName(), CI);
73     Operands.push_back(Arg);
74   }
75   // Pass nulls into any additional arguments...
76   for (; ArgNo != FT->getNumParams(); ++ArgNo)
77     Operands.push_back(Constant::getNullValue(FT->getParamType(ArgNo)));
78
79   std::string Name = CI->getName(); CI->setName("");
80   if (FT->getReturnType() == Type::VoidTy) Name.clear();
81   CallInst *NewCI = new CallInst(FCache, Operands, Name, CI);
82   if (!CI->use_empty()) {
83     Value *V = NewCI;
84     if (CI->getType() != NewCI->getType())
85       V = CastInst::createInferredCast(NewCI, CI->getType(), Name, CI);
86     CI->replaceAllUsesWith(V);
87   }
88   return NewCI;
89 }
90
91 void IntrinsicLowering::AddPrototypes(Module &M) {
92   for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
93     if (I->isExternal() && !I->use_empty())
94       switch (I->getIntrinsicID()) {
95       default: break;
96       case Intrinsic::setjmp:
97         EnsureFunctionExists(M, "setjmp", I->arg_begin(), I->arg_end(),
98                              Type::IntTy);
99         break;
100       case Intrinsic::longjmp:
101         EnsureFunctionExists(M, "longjmp", I->arg_begin(), I->arg_end(),
102                              Type::VoidTy);
103         break;
104       case Intrinsic::siglongjmp:
105         EnsureFunctionExists(M, "abort", I->arg_end(), I->arg_end(),
106                              Type::VoidTy);
107         break;
108       case Intrinsic::memcpy_i32:
109       case Intrinsic::memcpy_i64:
110         EnsureFunctionExists(M, "memcpy", I->arg_begin(), --I->arg_end(),
111                              I->arg_begin()->getType());
112         break;
113       case Intrinsic::memmove_i32:
114       case Intrinsic::memmove_i64:
115         EnsureFunctionExists(M, "memmove", I->arg_begin(), --I->arg_end(),
116                              I->arg_begin()->getType());
117         break;
118       case Intrinsic::memset_i32:
119       case Intrinsic::memset_i64:
120         M.getOrInsertFunction("memset", PointerType::get(Type::SByteTy),
121                               PointerType::get(Type::SByteTy),
122                               Type::IntTy, (--(--I->arg_end()))->getType(),
123                               (Type *)0);
124         break;
125       case Intrinsic::isunordered_f32:
126       case Intrinsic::isunordered_f64:
127         EnsureFunctionExists(M, "isunordered", I->arg_begin(), I->arg_end(),
128                              Type::BoolTy);
129         break;
130       case Intrinsic::sqrt_f32:
131       case Intrinsic::sqrt_f64:
132         if(I->arg_begin()->getType() == Type::FloatTy)
133           EnsureFunctionExists(M, "sqrtf", I->arg_begin(), I->arg_end(),
134                                Type::FloatTy);
135         else
136           EnsureFunctionExists(M, "sqrt", I->arg_begin(), I->arg_end(),
137                                Type::DoubleTy);
138         break;
139       }
140 }
141
142 /// LowerBSWAP - Emit the code to lower bswap of V before the specified
143 /// instruction IP.
144 static Value *LowerBSWAP(Value *V, Instruction *IP) {
145   assert(V->getType()->isInteger() && "Can't bswap a non-integer type!");
146
147   unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
148   
149   switch(BitSize) {
150   default: assert(0 && "Unhandled type size of value to byteswap!");
151   case 16: {
152     Value *Tmp1 = new ShiftInst(Instruction::Shl, V,
153                                 ConstantInt::get(Type::UByteTy,8),"bswap.2",IP);
154     Value *Tmp2 = new ShiftInst(Instruction::LShr, V,
155                                 ConstantInt::get(Type::UByteTy,8),"bswap.1",IP);
156     V = BinaryOperator::createOr(Tmp1, Tmp2, "bswap.i16", IP);
157     break;
158   }
159   case 32: {
160     Value *Tmp4 = new ShiftInst(Instruction::Shl, V,
161                               ConstantInt::get(Type::UByteTy,24),"bswap.4", IP);
162     Value *Tmp3 = new ShiftInst(Instruction::Shl, V,
163                               ConstantInt::get(Type::UByteTy,8),"bswap.3",IP);
164     Value *Tmp2 = new ShiftInst(Instruction::LShr, V,
165                               ConstantInt::get(Type::UByteTy,8),"bswap.2",IP);
166     Value *Tmp1 = new ShiftInst(Instruction::LShr, V,
167                               ConstantInt::get(Type::UByteTy,24),"bswap.1", IP);
168     Tmp3 = BinaryOperator::createAnd(Tmp3, 
169                                      ConstantInt::get(Type::UIntTy, 0xFF0000),
170                                      "bswap.and3", IP);
171     Tmp2 = BinaryOperator::createAnd(Tmp2, 
172                                      ConstantInt::get(Type::UIntTy, 0xFF00),
173                                      "bswap.and2", IP);
174     Tmp4 = BinaryOperator::createOr(Tmp4, Tmp3, "bswap.or1", IP);
175     Tmp2 = BinaryOperator::createOr(Tmp2, Tmp1, "bswap.or2", IP);
176     V = BinaryOperator::createOr(Tmp4, Tmp3, "bswap.i32", IP);
177     break;
178   }
179   case 64: {
180     Value *Tmp8 = new ShiftInst(Instruction::Shl, V,
181                               ConstantInt::get(Type::UByteTy,56),"bswap.8", IP);
182     Value *Tmp7 = new ShiftInst(Instruction::Shl, V,
183                               ConstantInt::get(Type::UByteTy,40),"bswap.7", IP);
184     Value *Tmp6 = new ShiftInst(Instruction::Shl, V,
185                               ConstantInt::get(Type::UByteTy,24),"bswap.6", IP);
186     Value *Tmp5 = new ShiftInst(Instruction::Shl, V,
187                               ConstantInt::get(Type::UByteTy,8),"bswap.5", IP);
188     Value* Tmp4 = new ShiftInst(Instruction::LShr, V,
189                               ConstantInt::get(Type::UByteTy,8),"bswap.4", IP);
190     Value* Tmp3 = new ShiftInst(Instruction::LShr, V,
191                               ConstantInt::get(Type::UByteTy,24),"bswap.3", IP);
192     Value* Tmp2 = new ShiftInst(Instruction::LShr, V,
193                               ConstantInt::get(Type::UByteTy,40),"bswap.2", IP);
194     Value* Tmp1 = new ShiftInst(Instruction::LShr, V,
195                               ConstantInt::get(Type::UByteTy,56),"bswap.1", IP);
196     Tmp7 = BinaryOperator::createAnd(Tmp7,
197                              ConstantInt::get(Type::ULongTy, 
198                                0xFF000000000000ULL),
199                              "bswap.and7", IP);
200     Tmp6 = BinaryOperator::createAnd(Tmp6,
201                              ConstantInt::get(Type::ULongTy, 0xFF0000000000ULL),
202                              "bswap.and6", IP);
203     Tmp5 = BinaryOperator::createAnd(Tmp5,
204                              ConstantInt::get(Type::ULongTy, 0xFF00000000ULL),
205                              "bswap.and5", IP);
206     Tmp4 = BinaryOperator::createAnd(Tmp4,
207                              ConstantInt::get(Type::ULongTy, 0xFF000000ULL),
208                              "bswap.and4", IP);
209     Tmp3 = BinaryOperator::createAnd(Tmp3,
210                              ConstantInt::get(Type::ULongTy, 0xFF0000ULL),
211                              "bswap.and3", IP);
212     Tmp2 = BinaryOperator::createAnd(Tmp2,
213                              ConstantInt::get(Type::ULongTy, 0xFF00ULL),
214                              "bswap.and2", IP);
215     Tmp8 = BinaryOperator::createOr(Tmp8, Tmp7, "bswap.or1", IP);
216     Tmp6 = BinaryOperator::createOr(Tmp6, Tmp5, "bswap.or2", IP);
217     Tmp4 = BinaryOperator::createOr(Tmp4, Tmp3, "bswap.or3", IP);
218     Tmp2 = BinaryOperator::createOr(Tmp2, Tmp1, "bswap.or4", IP);
219     Tmp8 = BinaryOperator::createOr(Tmp8, Tmp6, "bswap.or5", IP);
220     Tmp4 = BinaryOperator::createOr(Tmp4, Tmp2, "bswap.or6", IP);
221     V = BinaryOperator::createOr(Tmp8, Tmp4, "bswap.i64", IP);
222     break;
223   }
224   }
225   return V;
226 }
227
228 /// LowerCTPOP - Emit the code to lower ctpop of V before the specified
229 /// instruction IP.
230 static Value *LowerCTPOP(Value *V, Instruction *IP) {
231   assert(V->getType()->isInteger() && "Can't ctpop a non-integer type!");
232
233   static const uint64_t MaskValues[6] = {
234     0x5555555555555555ULL, 0x3333333333333333ULL,
235     0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL,
236     0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL
237   };
238
239   unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
240
241   for (unsigned i = 1, ct = 0; i != BitSize; i <<= 1, ++ct) {
242     Value *MaskCst =
243       ConstantExpr::getCast(ConstantInt::get(Type::ULongTy, MaskValues[ct]),
244                                              V->getType());
245     Value *LHS = BinaryOperator::createAnd(V, MaskCst, "cppop.and1", IP);
246     Value *VShift = new ShiftInst(Instruction::LShr, V,
247                       ConstantInt::get(Type::UByteTy, i), "ctpop.sh", IP);
248     Value *RHS = BinaryOperator::createAnd(VShift, MaskCst, "cppop.and2", IP);
249     V = BinaryOperator::createAdd(LHS, RHS, "ctpop.step", IP);
250   }
251
252   return V;
253 }
254
255 /// LowerCTLZ - Emit the code to lower ctlz of V before the specified
256 /// instruction IP.
257 static Value *LowerCTLZ(Value *V, Instruction *IP) {
258
259   unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
260   for (unsigned i = 1; i != BitSize; i <<= 1) {
261     Value *ShVal = ConstantInt::get(Type::UByteTy, i);
262     ShVal = new ShiftInst(Instruction::LShr, V, ShVal, "ctlz.sh", IP);
263     V = BinaryOperator::createOr(V, ShVal, "ctlz.step", IP);
264   }
265
266   V = BinaryOperator::createNot(V, "", IP);
267   return LowerCTPOP(V, IP);
268 }
269
270
271
272 void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
273   Function *Callee = CI->getCalledFunction();
274   assert(Callee && "Cannot lower an indirect call!");
275
276   switch (Callee->getIntrinsicID()) {
277   case Intrinsic::not_intrinsic:
278     std::cerr << "Cannot lower a call to a non-intrinsic function '"
279               << Callee->getName() << "'!\n";
280     abort();
281   default:
282     std::cerr << "Error: Code generator does not support intrinsic function '"
283               << Callee->getName() << "'!\n";
284     abort();
285
286     // The setjmp/longjmp intrinsics should only exist in the code if it was
287     // never optimized (ie, right out of the CFE), or if it has been hacked on
288     // by the lowerinvoke pass.  In both cases, the right thing to do is to
289     // convert the call to an explicit setjmp or longjmp call.
290   case Intrinsic::setjmp: {
291     static Function *SetjmpFCache = 0;
292     static const unsigned castOpcodes[] = { Instruction::BitCast };
293     Value *V = ReplaceCallWith("setjmp", CI, CI->op_begin()+1, CI->op_end(),
294                                castOpcodes, Type::IntTy, SetjmpFCache);
295     if (CI->getType() != Type::VoidTy)
296       CI->replaceAllUsesWith(V);
297     break;
298   }
299   case Intrinsic::sigsetjmp:
300      if (CI->getType() != Type::VoidTy)
301        CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
302      break;
303
304   case Intrinsic::longjmp: {
305     static Function *LongjmpFCache = 0;
306     static const unsigned castOpcodes[] = 
307       { Instruction::BitCast, 0 };
308     ReplaceCallWith("longjmp", CI, CI->op_begin()+1, CI->op_end(),
309                     castOpcodes, Type::VoidTy, LongjmpFCache);
310     break;
311   }
312
313   case Intrinsic::siglongjmp: {
314     // Insert the call to abort
315     static Function *AbortFCache = 0;
316     static const unsigned castOpcodes[] =
317       { Instruction::BitCast, 0 };
318     ReplaceCallWith("abort", CI, CI->op_end(), CI->op_end(), 
319                     castOpcodes, Type::VoidTy, AbortFCache);
320     break;
321   }
322   case Intrinsic::ctpop_i8:
323   case Intrinsic::ctpop_i16:
324   case Intrinsic::ctpop_i32:
325   case Intrinsic::ctpop_i64:
326     CI->replaceAllUsesWith(LowerCTPOP(CI->getOperand(1), CI));
327     break;
328
329   case Intrinsic::bswap_i16:
330   case Intrinsic::bswap_i32:
331   case Intrinsic::bswap_i64:
332     CI->replaceAllUsesWith(LowerBSWAP(CI->getOperand(1), CI));
333     break;
334     
335   case Intrinsic::ctlz_i8:
336   case Intrinsic::ctlz_i16:
337   case Intrinsic::ctlz_i32:
338   case Intrinsic::ctlz_i64:
339     CI->replaceAllUsesWith(LowerCTLZ(CI->getOperand(1), CI));
340     break;
341
342   case Intrinsic::cttz_i8:
343   case Intrinsic::cttz_i16:
344   case Intrinsic::cttz_i32:
345   case Intrinsic::cttz_i64: {
346     // cttz(x) -> ctpop(~X & (X-1))
347     Value *Src = CI->getOperand(1);
348     Value *NotSrc = BinaryOperator::createNot(Src, Src->getName()+".not", CI);
349     Value *SrcM1  = ConstantInt::get(Src->getType(), 1);
350     SrcM1 = BinaryOperator::createSub(Src, SrcM1, "", CI);
351     Src = LowerCTPOP(BinaryOperator::createAnd(NotSrc, SrcM1, "", CI), CI);
352     CI->replaceAllUsesWith(Src);
353     break;
354   }
355
356   case Intrinsic::stacksave:
357   case Intrinsic::stackrestore: {
358     static bool Warned = false;
359     if (!Warned)
360       std::cerr << "WARNING: this target does not support the llvm.stack"
361        << (Callee->getIntrinsicID() == Intrinsic::stacksave ?
362            "save" : "restore") << " intrinsic.\n";
363     Warned = true;
364     if (Callee->getIntrinsicID() == Intrinsic::stacksave)
365       CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
366     break;
367   }
368     
369   case Intrinsic::returnaddress:
370   case Intrinsic::frameaddress:
371     std::cerr << "WARNING: this target does not support the llvm."
372               << (Callee->getIntrinsicID() == Intrinsic::returnaddress ?
373                   "return" : "frame") << "address intrinsic.\n";
374     CI->replaceAllUsesWith(ConstantPointerNull::get(
375                                             cast<PointerType>(CI->getType())));
376     break;
377
378   case Intrinsic::prefetch:
379     break;    // Simply strip out prefetches on unsupported architectures
380
381   case Intrinsic::pcmarker:
382     break;    // Simply strip out pcmarker on unsupported architectures
383   case Intrinsic::readcyclecounter: {
384     std::cerr << "WARNING: this target does not support the llvm.readcyclecoun"
385               << "ter intrinsic.  It is being lowered to a constant 0\n";
386     CI->replaceAllUsesWith(ConstantInt::get(Type::ULongTy, 0));
387     break;
388   }
389
390   case Intrinsic::dbg_stoppoint:
391   case Intrinsic::dbg_region_start:
392   case Intrinsic::dbg_region_end:
393   case Intrinsic::dbg_func_start:
394   case Intrinsic::dbg_declare:
395     break;    // Simply strip out debugging intrinsics
396
397   case Intrinsic::memcpy_i32: {
398     // The memcpy intrinsic take an extra alignment argument that the memcpy
399     // libc function does not.
400     static unsigned opcodes[] = 
401       { Instruction::BitCast, Instruction::BitCast, Instruction::BitCast };
402     // FIXME:
403     // if (target_is_64_bit) opcodes[2] = Instruction::ZExt;
404     // else opcodes[2] = Instruction::BitCast;
405     static Function *MemcpyFCache = 0;
406     ReplaceCallWith("memcpy", CI, CI->op_begin()+1, CI->op_end()-1,
407                     opcodes, (*(CI->op_begin()+1))->getType(), MemcpyFCache);
408     break;
409   }
410   case Intrinsic::memcpy_i64: {
411     static unsigned opcodes[] = 
412       { Instruction::BitCast, Instruction::BitCast, Instruction::Trunc };
413     // FIXME:
414     // if (target_is_64_bit) opcodes[2] = Instruction::BitCast;
415     // else opcodes[2] = Instruction::Trunc;
416     static Function *MemcpyFCache = 0;
417     ReplaceCallWith("memcpy", CI, CI->op_begin()+1, CI->op_end()-1,
418                      opcodes, (*(CI->op_begin()+1))->getType(), MemcpyFCache);
419     break;
420   }
421   case Intrinsic::memmove_i32: {
422     // The memmove intrinsic take an extra alignment argument that the memmove
423     // libc function does not.
424     static unsigned opcodes[] = 
425       { Instruction::BitCast, Instruction::BitCast, Instruction::BitCast };
426     // FIXME:
427     // if (target_is_64_bit) opcodes[2] = Instruction::ZExt;
428     // else opcodes[2] = Instruction::BitCast;
429     static Function *MemmoveFCache = 0;
430     ReplaceCallWith("memmove", CI, CI->op_begin()+1, CI->op_end()-1,
431                     opcodes, (*(CI->op_begin()+1))->getType(), MemmoveFCache);
432     break;
433   }
434   case Intrinsic::memmove_i64: {
435     // The memmove intrinsic take an extra alignment argument that the memmove
436     // libc function does not.
437     static const unsigned opcodes[] = 
438       { Instruction::BitCast, Instruction::BitCast, Instruction::Trunc };
439     // if (target_is_64_bit) opcodes[2] = Instruction::BitCast;
440     // else opcodes[2] = Instruction::Trunc;
441     static Function *MemmoveFCache = 0;
442     ReplaceCallWith("memmove", CI, CI->op_begin()+1, CI->op_end()-1,
443                     opcodes, (*(CI->op_begin()+1))->getType(), MemmoveFCache);
444     break;
445   }
446   case Intrinsic::memset_i32: {
447     // The memset intrinsic take an extra alignment argument that the memset
448     // libc function does not.
449     static const unsigned opcodes[] = 
450       { Instruction::BitCast, Instruction::ZExt, Instruction::ZExt, 0 };
451     // if (target_is_64_bit) opcodes[2] = Instruction::BitCast;
452     // else opcodes[2] = Instruction::ZExt;
453     static Function *MemsetFCache = 0;
454     ReplaceCallWith("memset", CI, CI->op_begin()+1, CI->op_end()-1,
455                     opcodes, (*(CI->op_begin()+1))->getType(), MemsetFCache);
456   }
457   case Intrinsic::memset_i64: {
458     // The memset intrinsic take an extra alignment argument that the memset
459     // libc function does not.
460     static const unsigned opcodes[] = 
461       { Instruction::BitCast, Instruction::ZExt, Instruction::Trunc, 0 };
462     // if (target_is_64_bit) opcodes[2] = Instruction::BitCast;
463     // else opcodes[2] = Instruction::Trunc;
464     static Function *MemsetFCache = 0;
465     ReplaceCallWith("memset", CI, CI->op_begin()+1, CI->op_end()-1,
466                     opcodes, (*(CI->op_begin()+1))->getType(), MemsetFCache);
467     break;
468   }
469   case Intrinsic::isunordered_f32:
470   case Intrinsic::isunordered_f64: {
471     Value *L = CI->getOperand(1);
472     Value *R = CI->getOperand(2);
473
474     Value *LIsNan = new SetCondInst(Instruction::SetNE, L, L, "LIsNan", CI);
475     Value *RIsNan = new SetCondInst(Instruction::SetNE, R, R, "RIsNan", CI);
476     CI->replaceAllUsesWith(
477       BinaryOperator::create(Instruction::Or, LIsNan, RIsNan,
478                              "isunordered", CI));
479     break;
480   }
481   case Intrinsic::sqrt_f32: {
482     static const unsigned opcodes[] = { 0 };
483     static Function *sqrtfFCache = 0;
484     ReplaceCallWith("sqrtf", CI, CI->op_begin()+1, CI->op_end(),
485                     opcodes, Type::FloatTy, sqrtfFCache);
486     break;
487   }
488   case Intrinsic::sqrt_f64: {
489     static const unsigned opcodes[] =  { 0 };
490     static Function *sqrtFCache = 0;
491     ReplaceCallWith("sqrt", CI, CI->op_begin()+1, CI->op_end(),
492                     opcodes, Type::DoubleTy, sqrtFCache);
493     break;
494   }
495   }
496
497   assert(CI->use_empty() &&
498          "Lowering should have eliminated any uses of the intrinsic call!");
499   CI->eraseFromParent();
500 }