llvm.org GIT mirror llvm / 6c00b3f
[opaque pointer types] Pass value type to LoadInst creation. This cleans up all LoadInst creation in LLVM to explicitly pass the value type rather than deriving it from the pointer's element-type. Differential Revision: https://reviews.llvm.org/D57172 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352911 91177308-0d34-0410-b5e6-96231b3b80d8 James Y Knight 9 months ago
78 changed file(s) with 462 addition(s) and 366 deletion(s). Raw diff Collapse all Expand all
44034403 unsigned Align;
44044404 if (Error Err = parseAlignmentValue(Record[OpNum], Align))
44054405 return Err;
4406 I = new LoadInst(Op, "", Record[OpNum+1], Align, Ordering, SSID);
4406 I = new LoadInst(Ty, Op, "", Record[OpNum + 1], Align, Ordering, SSID);
44074407
44084408 InstructionList.push_back(I);
44094409 break;
380380 Addr->getType()->getPointerAddressSpace());
381381 Value *NewAddr = Builder.CreateBitCast(Addr, PT);
382382
383 auto *NewLI = Builder.CreateLoad(NewAddr);
383 auto *NewLI = Builder.CreateLoad(NewTy, NewAddr);
384384 NewLI->setAlignment(LI->getAlignment());
385385 NewLI->setVolatile(LI->isVolatile());
386386 NewLI->setAtomic(LI->getOrdering(), LI->getSyncScopeID());
17681768 // from call}
17691769 Type *FinalResultTy = I->getType();
17701770 Value *V = UndefValue::get(FinalResultTy);
1771 Value *ExpectedOut =
1772 Builder.CreateAlignedLoad(AllocaCASExpected, AllocaAlignment);
1771 Value *ExpectedOut = Builder.CreateAlignedLoad(
1772 CASExpected->getType(), AllocaCASExpected, AllocaAlignment);
17731773 Builder.CreateLifetimeEnd(AllocaCASExpected_i8, SizeVal64);
17741774 V = Builder.CreateInsertValue(V, ExpectedOut, 0);
17751775 V = Builder.CreateInsertValue(V, Result, 1);
17791779 if (UseSizedLibcall)
17801780 V = Builder.CreateBitOrPointerCast(Result, I->getType());
17811781 else {
1782 V = Builder.CreateAlignedLoad(AllocaResult, AllocaAlignment);
1782 V = Builder.CreateAlignedLoad(I->getType(), AllocaResult,
1783 AllocaAlignment);
17831784 Builder.CreateLifetimeEnd(AllocaResult_i8, SizeVal64);
17841785 }
17851786 I->replaceAllUsesWith(V);
212212 }
213213 case Intrinsic::gcread: {
214214 // Replace a read barrier with a simple load.
215 Value *Ld = new LoadInst(CI->getArgOperand(1), "", CI);
215 Value *Ld = new LoadInst(CI->getType(), CI->getArgOperand(1), "", CI);
216216 Ld->takeName(CI);
217217 CI->replaceAllUsesWith(Ld);
218218 CI->eraseFromParent();
12171217 "interleaved.wide.ptrcast");
12181218
12191219 // Create the wide load and update the MemorySSA.
1220 auto LI = Builder.CreateAlignedLoad(CI, InsertionPoint->getAlignment(),
1220 auto LI = Builder.CreateAlignedLoad(ILTy, CI, InsertionPoint->getAlignment(),
12211221 "interleaved.wide.load");
12221222 auto MSSAU = MemorySSAUpdater(&MSSA);
12231223 MemoryUse *MSSALoad = cast(MSSAU.createMemoryAccessBefore(
4343 Value *OffsetPtr =
4444 B.CreateGEP(Int8Ty, CI->getArgOperand(0), CI->getArgOperand(1));
4545 Value *OffsetPtrI32 = B.CreateBitCast(OffsetPtr, Int32PtrTy);
46 Value *OffsetI32 = B.CreateAlignedLoad(OffsetPtrI32, 4);
46 Value *OffsetI32 = B.CreateAlignedLoad(Int32Ty, OffsetPtrI32, 4);
4747
4848 Value *ResultPtr = B.CreateGEP(Int8Ty, CI->getArgOperand(0), OffsetI32);
4949
370370 if (!StackGuardVar)
371371 StackGuardVar =
372372 F.getParent()->getOrInsertGlobal("__stack_chk_guard", StackPtrTy);
373 return IRB.CreateLoad(StackGuardVar, "StackGuard");
373 return IRB.CreateLoad(StackPtrTy, StackGuardVar, "StackGuard");
374374 }
375375
376376 void SafeStack::findInsts(Function &F,
451451 ++NumUnsafeStackRestorePoints;
452452
453453 IRB.SetInsertPoint(I->getNextNode());
454 Value *CurrentTop = DynamicTop ? IRB.CreateLoad(DynamicTop) : StaticTop;
454 Value *CurrentTop =
455 DynamicTop ? IRB.CreateLoad(StackPtrTy, DynamicTop) : StaticTop;
455456 IRB.CreateStore(CurrentTop, UnsafeStackPtr);
456457 }
457458
460461
461462 void SafeStack::checkStackGuard(IRBuilder<> &IRB, Function &F, ReturnInst &RI,
462463 AllocaInst *StackGuardSlot, Value *StackGuard) {
463 Value *V = IRB.CreateLoad(StackGuardSlot);
464 Value *V = IRB.CreateLoad(StackPtrTy, StackGuardSlot);
464465 Value *Cmp = IRB.CreateICmpNE(StackGuard, V);
465466
466467 auto SuccessProb = BranchProbabilityInfo::getBranchProbStackProtector(true);
658659 uint64_t TySize = DL.getTypeAllocSize(Ty);
659660 Value *Size = IRB.CreateMul(ArraySize, ConstantInt::get(IntPtrTy, TySize));
660661
661 Value *SP = IRB.CreatePtrToInt(IRB.CreateLoad(UnsafeStackPtr), IntPtrTy);
662 Value *SP = IRB.CreatePtrToInt(IRB.CreateLoad(StackPtrTy, UnsafeStackPtr),
663 IntPtrTy);
662664 SP = IRB.CreateSub(SP, Size);
663665
664666 // Align the SP value to satisfy the AllocaInst, type and stack alignments.
696698
697699 if (II->getIntrinsicID() == Intrinsic::stacksave) {
698700 IRBuilder<> IRB(II);
699 Instruction *LI = IRB.CreateLoad(UnsafeStackPtr);
701 Instruction *LI = IRB.CreateLoad(StackPtrTy, UnsafeStackPtr);
700702 LI->takeName(II);
701703 II->replaceAllUsesWith(LI);
702704 II->eraseFromParent();
791793 // Load the current stack pointer (we'll also use it as a base pointer).
792794 // FIXME: use a dedicated register for it ?
793795 Instruction *BasePointer =
794 IRB.CreateLoad(UnsafeStackPtr, false, "unsafe_stack_ptr");
796 IRB.CreateLoad(StackPtrTy, UnsafeStackPtr, false, "unsafe_stack_ptr");
795797 assert(BasePointer->getType() == StackPtrTy);
796798
797799 AllocaInst *StackGuardSlot = nullptr;
142142
143143 // Short-cut if the mask is all-true.
144144 if (isa(Mask) && cast(Mask)->isAllOnesValue()) {
145 Value *NewI = Builder.CreateAlignedLoad(Ptr, AlignVal);
145 Value *NewI = Builder.CreateAlignedLoad(VecType, Ptr, AlignVal);
146146 CI->replaceAllUsesWith(NewI);
147147 CI->eraseFromParent();
148148 return;
165165 continue;
166166 Value *Gep =
167167 Builder.CreateInBoundsGEP(EltTy, FirstEltPtr, Builder.getInt32(Idx));
168 LoadInst *Load = Builder.CreateAlignedLoad(Gep, AlignVal);
168 LoadInst *Load = Builder.CreateAlignedLoad(EltTy, Gep, AlignVal);
169169 VResult =
170170 Builder.CreateInsertElement(VResult, Load, Builder.getInt32(Idx));
171171 }
197197
198198 Value *Gep =
199199 Builder.CreateInBoundsGEP(EltTy, FirstEltPtr, Builder.getInt32(Idx));
200 LoadInst *Load = Builder.CreateAlignedLoad(Gep, AlignVal);
200 LoadInst *Load = Builder.CreateAlignedLoad(EltTy, Gep, AlignVal);
201201 Value *NewVResult = Builder.CreateInsertElement(VResult, Load,
202202 Builder.getInt32(Idx));
203203
365365 Value *Src0 = CI->getArgOperand(3);
366366
367367 VectorType *VecType = cast(CI->getType());
368 Type *EltTy = VecType->getElementType();
368369
369370 IRBuilder<> Builder(CI->getContext());
370371 Instruction *InsertPt = CI;
386387 Value *Ptr = Builder.CreateExtractElement(Ptrs, Builder.getInt32(Idx),
387388 "Ptr" + Twine(Idx));
388389 LoadInst *Load =
389 Builder.CreateAlignedLoad(Ptr, AlignVal, "Load" + Twine(Idx));
390 Builder.CreateAlignedLoad(EltTy, Ptr, AlignVal, "Load" + Twine(Idx));
390391 VResult = Builder.CreateInsertElement(
391392 VResult, Load, Builder.getInt32(Idx), "Res" + Twine(Idx));
392393 }
417418 Value *Ptr = Builder.CreateExtractElement(Ptrs, Builder.getInt32(Idx),
418419 "Ptr" + Twine(Idx));
419420 LoadInst *Load =
420 Builder.CreateAlignedLoad(Ptr, AlignVal, "Load" + Twine(Idx));
421 Builder.CreateAlignedLoad(EltTy, Ptr, AlignVal, "Load" + Twine(Idx));
421422 Value *NewVResult = Builder.CreateInsertElement(VResult, Load,
422423 Builder.getInt32(Idx),
423424 "Res" + Twine(Idx));
311311 AtEntry.SetInsertPoint(IP->getParent(), IP);
312312
313313 // Initialize the map pointer and load the current head of the shadow stack.
314 Instruction *CurrentHead = AtEntry.CreateLoad(Head, "gc_currhead");
314 Instruction *CurrentHead =
315 AtEntry.CreateLoad(StackEntryTy->getPointerTo(), Head, "gc_currhead");
315316 Instruction *EntryMapPtr = CreateGEP(Context, AtEntry, ConcreteStackEntryTy,
316317 StackEntry, 0, 1, "gc_frame.map");
317318 AtEntry.CreateStore(FrameMap, EntryMapPtr);
352353 Instruction *EntryNextPtr2 =
353354 CreateGEP(Context, *AtExit, ConcreteStackEntryTy, StackEntry, 0, 0,
354355 "gc_frame.next");
355 Value *SavedHead = AtExit->CreateLoad(EntryNextPtr2, "gc_savedhead");
356 Value *SavedHead = AtExit->CreateLoad(StackEntryTy->getPointerTo(),
357 EntryNextPtr2, "gc_savedhead");
356358 AtExit->CreateStore(SavedHead, Head);
357359 }
358360
188188 Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 2, "__data");
189189
190190 // The exception values come back in context->__data[0].
191 Type *Int32Ty = Type::getInt32Ty(F.getContext());
191192 Value *ExceptionAddr = Builder.CreateConstGEP2_32(doubleUnderDataTy, FCData,
192193 0, 0, "exception_gep");
193 Value *ExnVal = Builder.CreateLoad(ExceptionAddr, true, "exn_val");
194 Value *ExnVal = Builder.CreateLoad(Int32Ty, ExceptionAddr, true, "exn_val");
194195 ExnVal = Builder.CreateIntToPtr(ExnVal, Builder.getInt8PtrTy());
195196
196197 Value *SelectorAddr = Builder.CreateConstGEP2_32(doubleUnderDataTy, FCData,
197198 0, 1, "exn_selector_gep");
198 Value *SelVal = Builder.CreateLoad(SelectorAddr, true, "exn_selector_val");
199 Value *SelVal =
200 Builder.CreateLoad(Int32Ty, SelectorAddr, true, "exn_selector_val");
199201
200202 substituteLPadValues(LPI, ExnVal, SelVal);
201203 }
321321 IRBuilder<> &B,
322322 bool *SupportsSelectionDAGSP = nullptr) {
323323 if (Value *Guard = TLI->getIRStackGuard(B))
324 return B.CreateLoad(Guard, true, "StackGuard");
324 return B.CreateLoad(B.getInt8PtrTy(), Guard, true, "StackGuard");
325325
326326 // Use SelectionDAG SSP handling, since there isn't an IR guard.
327327 //
416416 // Generate the function-based epilogue instrumentation.
417417 // The target provides a guard check function, generate a call to it.
418418 IRBuilder<> B(RI);
419 LoadInst *Guard = B.CreateLoad(AI, true, "Guard");
419 LoadInst *Guard = B.CreateLoad(B.getInt8PtrTy(), AI, true, "Guard");
420420 CallInst *Call = B.CreateCall(GuardCheck, {Guard});
421421 Call->setAttributes(GuardCheck->getAttributes());
422422 Call->setCallingConv(GuardCheck->getCallingConv());
471471 // Generate the stack protector instructions in the old basic block.
472472 IRBuilder<> B(BB);
473473 Value *Guard = getStackGuard(TLI, M, B);
474 LoadInst *LI2 = B.CreateLoad(AI, true);
474 LoadInst *LI2 = B.CreateLoad(B.getInt8PtrTy(), AI, true);
475475 Value *Cmp = B.CreateICmpEQ(Guard, LI2);
476476 auto SuccessProb =
477477 BranchProbabilityInfo::getBranchProbStackProtector(true);
343343 PersCI->setDoesNotThrow();
344344
345345 // Pseudocode: int selector = __wasm.landingpad_context.selector;
346 Instruction *Selector = IRB.CreateLoad(SelectorField, "selector");
346 Instruction *Selector =
347 IRB.CreateLoad(IRB.getInt32Ty(), SelectorField, "selector");
347348
348349 // Replace the return value from wasm.get.ehselector() with the selector value
349350 // loaded from __wasm_lpad_context.selector.
10781078 SpillSlot = new AllocaInst(PN->getType(), DL->getAllocaAddrSpace(), nullptr,
10791079 Twine(PN->getName(), ".wineh.spillslot"),
10801080 &F.getEntryBlock().front());
1081 Value *V = new LoadInst(SpillSlot, Twine(PN->getName(), ".wineh.reload"),
1081 Value *V = new LoadInst(PN->getType(), SpillSlot,
1082 Twine(PN->getName(), ".wineh.reload"),
10821083 &*PHIBlock->getFirstInsertionPt());
10831084 PN->replaceAllUsesWith(V);
10841085 return SpillSlot;
12201221 Value *&Load = Loads[IncomingBlock];
12211222 // Insert the load into the predecessor block
12221223 if (!Load)
1223 Load = new LoadInst(SpillSlot, Twine(V->getName(), ".wineh.reload"),
1224 Load = new LoadInst(V->getType(), SpillSlot,
1225 Twine(V->getName(), ".wineh.reload"),
12241226 /*Volatile=*/false, IncomingBlock->getTerminator());
12251227
12261228 U.set(Load);
12271229 } else {
12281230 // Reload right before the old use.
1229 auto *Load = new LoadInst(SpillSlot, Twine(V->getName(), ".wineh.reload"),
1231 auto *Load = new LoadInst(V->getType(), SpillSlot,
1232 Twine(V->getName(), ".wineh.reload"),
12301233 /*Volatile=*/false, UsingInst);
12311234 U.set(Load);
12321235 }
234234 assert(F.isDeclaration() && "Can't turn a definition into a stub.");
235235 assert(F.getParent() && "Function isn't in a module.");
236236 Module &M = *F.getParent();
237 FunctionType *FTy = F.getFunctionType();
238237 BasicBlock *EntryBlock = BasicBlock::Create(M.getContext(), "entry", &F);
239238 IRBuilder<> Builder(EntryBlock);
240 LoadInst *ImplAddr = Builder.CreateLoad(&ImplPointer);
239 LoadInst *ImplAddr = Builder.CreateLoad(F.getType(), &ImplPointer);
241240 std::vector CallArgs;
242241 for (auto &A : F.args())
243242 CallArgs.push_back(&A);
244 CallInst *Call = Builder.CreateCall(FTy, ImplAddr, CallArgs);
243 CallInst *Call = Builder.CreateCall(F.getFunctionType(), ImplAddr, CallArgs);
245244 Call->setTailCall();
246245 Call->setAttributes(F.getAttributes());
247246 if (F.getReturnType()->isVoidTy())
5252 IP = ++I->getIterator();
5353 assert(IP != BB.end() && "guaranteed by the findPointer");
5454 }
55 auto *NewLoad = new LoadInst(Ptr, "L", &*IP);
55 auto *NewLoad = new LoadInst(
56 cast(Ptr->getType())->getElementType(), Ptr, "L", &*IP);
5657
5758 // Only sample this load if it really matches the descriptor
5859 if (Pred.matches(Srcs, NewLoad))
11611161 static Value *UpgradeMaskedLoad(IRBuilder<> &Builder,
11621162 Value *Ptr, Value *Passthru, Value *Mask,
11631163 bool Aligned) {
1164 Type *ValTy = Passthru->getType();
11641165 // Cast the pointer to the right type.
1165 Ptr = Builder.CreateBitCast(Ptr,
1166 llvm::PointerType::getUnqual(Passthru->getType()));
1166 Ptr = Builder.CreateBitCast(Ptr, llvm::PointerType::getUnqual(ValTy));
11671167 unsigned Align =
11681168 Aligned ? cast(Passthru->getType())->getBitWidth() / 8 : 1;
11691169
11701170 // If the mask is all ones just emit a regular store.
11711171 if (const auto *C = dyn_cast(Mask))
11721172 if (C->isAllOnesValue())
1173 return Builder.CreateAlignedLoad(Ptr, Align);
1173 return Builder.CreateAlignedLoad(ValTy, Ptr, Align);
11741174
11751175 // Convert the mask from an integer type to a vector of i1.
11761176 unsigned NumElts = Passthru->getType()->getVectorNumElements();
21982198 Type *VT = VectorType::get(EltTy, NumSrcElts);
21992199 Value *Op = Builder.CreatePointerCast(CI->getArgOperand(0),
22002200 PointerType::getUnqual(VT));
2201 Value *Load = Builder.CreateAlignedLoad(Op, 1);
2201 Value *Load = Builder.CreateAlignedLoad(VT, Op, 1);
22022202 if (NumSrcElts == 2)
22032203 Rep = Builder.CreateShuffleVector(Load, UndefValue::get(Load->getType()),
22042204 { 0, 1, 0, 1 });
29442944 // Convert the type of the pointer to a pointer to the stored type.
29452945 Value *BC =
29462946 Builder.CreateBitCast(Ptr, PointerType::getUnqual(VTy), "cast");
2947 LoadInst *LI = Builder.CreateAlignedLoad(BC, VTy->getBitWidth() / 8);
2947 LoadInst *LI = Builder.CreateAlignedLoad(VTy, BC, VTy->getBitWidth() / 8);
29482948 LI->setMetadata(M->getMDKindID("nontemporal"), Node);
29492949 Rep = LI;
29502950 } else if (IsX86 &&
492492 for (const auto &IPI : InsertPts) {
493493 // Create the load of the global variable.
494494 IRBuilder<> Builder(IPI.first);
495 LoadInst *LoadedCst = Builder.CreateLoad(&PromotedGV);
495 LoadInst *LoadedCst =
496 Builder.CreateLoad(PromotedGV.getValueType(), &PromotedGV);
496497 LLVM_DEBUG(dbgs() << "**********\n");
497498 LLVM_DEBUG(dbgs() << "New def: ");
498499 LLVM_DEBUG(LoadedCst->print(dbgs()));
805805 Type *I32Ty = Builder.getInt32Ty();
806806 Type *PT = PointerType::get(I32Ty, I.getPointerAddressSpace());
807807 Value *BitCast= Builder.CreateBitCast(I.getPointerOperand(), PT);
808 LoadInst *WidenLoad = Builder.CreateLoad(BitCast);
808 LoadInst *WidenLoad = Builder.CreateLoad(I32Ty, BitCast);
809809 WidenLoad->copyMetadata(I);
810810
811811 // If we have range metadata, we need to convert the type, and not make
13561356 if (!isSin) { // CI->cos, UI->sin
13571357 B.SetInsertPoint(&*ItOld);
13581358 UI->replaceAllUsesWith(&*Call);
1359 Instruction *Reload = B.CreateLoad(Alloc);
1359 Instruction *Reload = B.CreateLoad(Alloc->getAllocatedType(), Alloc);
13601360 CI->replaceAllUsesWith(Reload);
13611361 UI->eraseFromParent();
13621362 CI->eraseFromParent();
13631363 } else { // CI->sin, UI->cos
1364 Instruction *Reload = B.CreateLoad(Alloc);
1364 Instruction *Reload = B.CreateLoad(Alloc->getAllocatedType(), Alloc);
13651365 UI->replaceAllUsesWith(Reload);
13661366 CI->replaceAllUsesWith(Call);
13671367 UI->eraseFromParent();
131131 KernArgBaseAlign);
132132
133133 Value *ArgPtr;
134 Type *AdjustedArgTy;
134135 if (DoShiftOpt) { // FIXME: Handle aggregate types
135136 // Since we don't have sub-dword scalar loads, avoid doing an extload by
136137 // loading earlier than the argument address, and extracting the relevant
143144 KernArgSegment,
144145 AlignDownOffset,
145146 Arg.getName() + ".kernarg.offset.align.down");
146 ArgPtr = Builder.CreateBitCast(ArgPtr,
147 Builder.getInt32Ty()->getPointerTo(AS),
148 ArgPtr->getName() + ".cast");
147 AdjustedArgTy = Builder.getInt32Ty();
149148 } else {
150149 ArgPtr = Builder.CreateConstInBoundsGEP1_64(
151150 KernArgSegment,
152151 EltOffset,
153152 Arg.getName() + ".kernarg.offset");
154 ArgPtr = Builder.CreateBitCast(ArgPtr, ArgTy->getPointerTo(AS),
155 ArgPtr->getName() + ".cast");
153 AdjustedArgTy = ArgTy;
156154 }
157155
158156 if (IsV3 && Size >= 32) {
159157 V4Ty = VectorType::get(VT->getVectorElementType(), 4);
160158 // Use the hack that clang uses to avoid SelectionDAG ruining v3 loads
161 ArgPtr = Builder.CreateBitCast(ArgPtr, V4Ty->getPointerTo(AS));
162 }
163
164 LoadInst *Load = Builder.CreateAlignedLoad(ArgPtr, AdjustedAlign);
159 AdjustedArgTy = V4Ty;
160 }
161
162 ArgPtr = Builder.CreateBitCast(ArgPtr, AdjustedArgTy->getPointerTo(AS),
163 ArgPtr->getName() + ".cast");
164 LoadInst *Load =
165 Builder.CreateAlignedLoad(AdjustedArgTy, ArgPtr, AdjustedAlign);
165166 Load->setMetadata(LLVMContext::MD_invariant_load, MDNode::get(Ctx, {}));
166167
167168 MDBuilder MDB(Ctx);
244244 // 32-bit and extract sequence is already present, and it is probably easier
245245 // to CSE this. The loads should be mergable later anyway.
246246 Value *GEPXY = Builder.CreateConstInBoundsGEP1_64(CastDispatchPtr, 1);
247 LoadInst *LoadXY = Builder.CreateAlignedLoad(GEPXY, 4);
247 LoadInst *LoadXY = Builder.CreateAlignedLoad(I32Ty, GEPXY, 4);
248248
249249 Value *GEPZU = Builder.CreateConstInBoundsGEP1_64(CastDispatchPtr, 2);
250 LoadInst *LoadZU = Builder.CreateAlignedLoad(GEPZU, 4);
250 LoadInst *LoadZU = Builder.CreateAlignedLoad(I32Ty, GEPZU, 4);
251251
252252 MDNode *MD = MDNode::get(Mod->getContext(), None);
253253 LoadXY->setMetadata(LLVMContext::MD_invariant_load, MD);
425425 Value *Index = calculateVectorIndex(Ptr, GEPVectorIdx);
426426
427427 Value *BitCast = Builder.CreateBitCast(Alloca, VecPtrTy);
428 Value *VecValue = Builder.CreateLoad(BitCast);
428 Value *VecValue = Builder.CreateLoad(VectorTy, BitCast);
429429 Value *ExtractElement = Builder.CreateExtractElement(VecValue, Index);
430430 Inst->replaceAllUsesWith(ExtractElement);
431431 Inst->eraseFromParent();
440440 Value *Ptr = SI->getPointerOperand();
441441 Value *Index = calculateVectorIndex(Ptr, GEPVectorIdx);
442442 Value *BitCast = Builder.CreateBitCast(Alloca, VecPtrTy);
443 Value *VecValue = Builder.CreateLoad(BitCast);
443 Value *VecValue = Builder.CreateLoad(VectorTy, BitCast);
444444 Value *NewVecValue = Builder.CreateInsertElement(VecValue,
445445 SI->getValueOperand(),
446446 Index);
687687 }
688688
689689 static LoadInst *CreateLoadIns(IRBuilder &IRB, LoadInst &BaseLoad,
690 const Type *LoadTy) {
690 Type *LoadTy) {
691691 const unsigned AddrSpace = BaseLoad.getPointerAddressSpace();
692692
693693 Value *VecPtr = IRB.CreateBitCast(BaseLoad.getPointerOperand(),
694694 LoadTy->getPointerTo(AddrSpace));
695 return IRB.CreateAlignedLoad(VecPtr, BaseLoad.getAlignment());
695 return IRB.CreateAlignedLoad(LoadTy, VecPtr, BaseLoad.getAlignment());
696696 }
697697
698698 Instruction *ARMParallelDSP::CreateSMLADCall(LoadInst *VecLd0, LoadInst *VecLd1,
708708 ++BasicBlock::iterator(InsertAfter));
709709
710710 // Replace the reduction chain with an intrinsic call
711 const Type *Ty = IntegerType::get(M->getContext(), 32);
711 Type *Ty = IntegerType::get(M->getContext(), 32);
712712 LoadInst *NewLd0 = CreateLoadIns(Builder, VecLd0[0], Ty);
713713 LoadInst *NewLd1 = CreateLoadIns(Builder, VecLd1[0], Ty);
714714 Value* Args[] = { NewLd0, NewLd1, Acc };
168168 Value *ArgInParam = new AddrSpaceCastInst(
169169 Arg, PointerType::get(StructType, ADDRESS_SPACE_PARAM), Arg->getName(),
170170 FirstInst);
171 LoadInst *LI = new LoadInst(ArgInParam, Arg->getName(), FirstInst);
171 LoadInst *LI =
172 new LoadInst(StructType, ArgInParam, Arg->getName(), FirstInst);
172173 new StoreInst(LI, AllocA, FirstInst);
173174 }
174175
444444
445445 // Post-invoke
446446 // %__THREW__.val = __THREW__; __THREW__ = 0;
447 Value *Threw = IRB.CreateLoad(ThrewGV, ThrewGV->getName() + ".val");
447 Value *Threw =
448 IRB.CreateLoad(IRB.getInt32Ty(), ThrewGV, ThrewGV->getName() + ".val");
448449 IRB.CreateStore(IRB.getInt32(0), ThrewGV);
449450 return Threw;
450451 }
547548 BasicBlock *ElseBB1 = BasicBlock::Create(C, "if.else1", F);
548549 BasicBlock *EndBB1 = BasicBlock::Create(C, "if.end", F);
549550 Value *ThrewCmp = IRB.CreateICmpNE(Threw, IRB.getInt32(0));
550 Value *ThrewValue =
551 IRB.CreateLoad(ThrewValueGV, ThrewValueGV->getName() + ".val");
551 Value *ThrewValue = IRB.CreateLoad(IRB.getInt32Ty(), ThrewValueGV,
552 ThrewValueGV->getName() + ".val");
552553 Value *ThrewValueCmp = IRB.CreateICmpNE(ThrewValue, IRB.getInt32(0));
553554 Value *Cmp1 = IRB.CreateAnd(ThrewCmp, ThrewValueCmp, "cmp1");
554555 IRB.CreateCondBr(Cmp1, ThenBB1, ElseBB1);
560561 BasicBlock *EndBB2 = BasicBlock::Create(C, "if.end2", F);
561562 Value *ThrewInt = IRB.CreateIntToPtr(Threw, Type::getInt32PtrTy(C),
562563 Threw->getName() + ".i32p");
563 Value *LoadedThrew =
564 IRB.CreateLoad(ThrewInt, ThrewInt->getName() + ".loaded");
564 Value *LoadedThrew = IRB.CreateLoad(IRB.getInt32Ty(), ThrewInt,
565 ThrewInt->getName() + ".loaded");
565566 Value *ThenLabel = IRB.CreateCall(
566567 TestSetjmpF, {LoadedThrew, SetjmpTable, SetjmpTableSize}, "label");
567568 Value *Cmp2 = IRB.CreateICmpEQ(ThenLabel, IRB.getInt32(0));
2536125361 // We must restrict the ordering to avoid generating loads with Release or
2536225362 // ReleaseAcquire orderings.
2536325363 auto Order = AtomicCmpXchgInst::getStrongestFailureOrdering(AI->getOrdering());
25364 auto Ptr = AI->getPointerOperand();
2536525364
2536625365 // Before the load we need a fence. Here is an example lifted from
2536725366 // http://www.hpl.hp.com/techreports/2012/HPL-2012-68.pdf showing why a fence
2539625395 Builder.CreateCall(MFence, {});
2539725396
2539825397 // Finally we can emit the atomic load.
25399 LoadInst *Loaded = Builder.CreateAlignedLoad(Ptr,
25400 AI->getType()->getPrimitiveSizeInBits());
25398 LoadInst *Loaded =
25399 Builder.CreateAlignedLoad(AI->getType(), AI->getPointerOperand(),
25400 AI->getType()->getPrimitiveSizeInBits());
2540125401 Loaded->setAtomic(Order, SSID);
2540225402 AI->replaceAllUsesWith(Loaded);
2540325403 AI->eraseFromParent();
192192
193193 // Decompose the load instruction.
194194 LoadInst *LI = cast(VecInst);
195 Type *VecBasePtrTy = SubVecTy->getPointerTo(LI->getPointerAddressSpace());
195 Type *VecBaseTy, *VecBasePtrTy;
196196 Value *VecBasePtr;
197197 unsigned int NumLoads = NumSubVectors;
198198 // In the case of stride 3 with a vector of 32 elements load the information
200200 // [0,1...,VF/2-1,VF/2+VF,VF/2+VF+1,...,2VF-1]
201201 unsigned VecLength = DL.getTypeSizeInBits(VecWidth);
202202 if (VecLength == 768 || VecLength == 1536) {
203 Type *VecTran =
204 VectorType::get(Type::getInt8Ty(LI->getContext()), 16)->getPointerTo();
205 VecBasePtr = Builder.CreateBitCast(LI->getPointerOperand(), VecTran);
203 VecBaseTy = VectorType::get(Type::getInt8Ty(LI->getContext()), 16);
204 VecBasePtrTy = VecBaseTy->getPointerTo(LI->getPointerAddressSpace());
205 VecBasePtr = Builder.CreateBitCast(LI->getPointerOperand(), VecBasePtrTy);
206206 NumLoads = NumSubVectors * (VecLength / 384);
207 } else
207 } else {
208 VecBaseTy = SubVecTy;
209 VecBasePtrTy = VecBaseTy->getPointerTo(LI->getPointerAddressSpace());
208210 VecBasePtr = Builder.CreateBitCast(LI->getPointerOperand(), VecBasePtrTy);
211 }
209212 // Generate N loads of T type.
210213 for (unsigned i = 0; i < NumLoads; i++) {
211214 // TODO: Support inbounds GEP.
212215 Value *NewBasePtr = Builder.CreateGEP(VecBasePtr, Builder.getInt32(i));
213216 Instruction *NewLoad =
214 Builder.CreateAlignedLoad(NewBasePtr, LI->getAlignment());
217 Builder.CreateAlignedLoad(VecBaseTy, NewBasePtr, LI->getAlignment());
215218 DecomposedVectors.push_back(NewLoad);
216219 }
217220 }
431431 // Next = [fs:00]
432432 Constant *FSZero =
433433 Constant::getNullValue(LinkTy->getPointerTo()->getPointerTo(257));
434 Value *Next = Builder.CreateLoad(FSZero);
434 Value *Next = Builder.CreateLoad(LinkTy->getPointerTo(), FSZero);
435435 Builder.CreateStore(Next, Builder.CreateStructGEP(LinkTy, Link, 0));
436436 // [fs:00] = Link
437437 Builder.CreateStore(Link, FSZero);
446446 }
447447 Type *LinkTy = getEHLinkRegistrationType();
448448 // [fs:00] = Link->Next
449 Value *Next =
450 Builder.CreateLoad(Builder.CreateStructGEP(LinkTy, Link, 0));
449 Value *Next = Builder.CreateLoad(LinkTy->getPointerTo(),
450 Builder.CreateStructGEP(LinkTy, Link, 0));
451451 Constant *FSZero =
452452 Constant::getNullValue(LinkTy->getPointerTo()->getPointerTo(257));
453453 Builder.CreateStore(Next, FSZero);
782782 if (InCleanup) {
783783 Value *StateField =
784784 Builder.CreateStructGEP(nullptr, RegNode, StateFieldIndex);
785 State = Builder.CreateLoad(StateField);
785 State = Builder.CreateLoad(Builder.getInt32Ty(), StateField);
786786 } else {
787787 State = Builder.getInt32(getStateForCallSite(BlockColors, FuncInfo, CS));
788788 }
4848 Builder.SetInsertPoint(SubFn);
4949 auto *FramePtr = Builder.CreateBitCast(FrameRaw, FramePtrTy);
5050 auto *Gep = Builder.CreateConstInBoundsGEP2_32(FrameTy, FramePtr, 0, Index);
51 auto *Load = Builder.CreateLoad(Gep);
51 auto *Load = Builder.CreateLoad(FrameTy->getElementType(Index), Gep);
5252
5353 SubFn->replaceAllUsesWith(Load);
5454 }
9696 Builder.SetInsertPoint(II);
9797 auto *BCI = Builder.CreateBitCast(Operand, FramePtrTy);
9898 auto *Gep = Builder.CreateConstInBoundsGEP1_32(FrameTy, BCI, 0);
99 auto *Load = Builder.CreateLoad(Gep);
99 auto *Load = Builder.CreateLoad(FrameTy, Gep);
100100 auto *Cond = Builder.CreateICmpEQ(Load, NullPtr);
101101
102102 II->replaceAllUsesWith(Cond);
470470 static Instruction *insertSpills(SpillInfo &Spills, coro::Shape &Shape) {
471471 auto *CB = Shape.CoroBegin;
472472 IRBuilder<> Builder(CB->getNextNode());
473 PointerType *FramePtrTy = Shape.FrameTy->getPointerTo();
473 StructType *FrameTy = Shape.FrameTy;
474 PointerType *FramePtrTy = FrameTy->getPointerTo();
474475 auto *FramePtr =
475476 cast(Builder.CreateBitCast(CB, FramePtrTy, "FramePtr"));
476 Type *FrameTy = FramePtrTy->getElementType();
477477
478478 Value *CurrentValue = nullptr;
479479 BasicBlock *CurrentBlock = nullptr;
500500 Twine(".reload.addr"));
501501 return isa(CurrentValue)
502502 ? G
503 : Builder.CreateLoad(G,
503 : Builder.CreateLoad(FrameTy->getElementType(Index), G,
504504 CurrentValue->getName() + Twine(".reload"));
505505 };
506506
9292 auto *FrameTy = Shape.FrameTy;
9393 auto *GepIndex = Builder.CreateConstInBoundsGEP2_32(
9494 FrameTy, FramePtr, 0, coro::Shape::IndexField, "index.addr");
95 auto *Index = Builder.CreateLoad(GepIndex, "index");
95 auto *Index = Builder.CreateLoad(Shape.getIndexType(), GepIndex, "index");
9696 auto *Switch =
9797 Builder.CreateSwitch(Index, UnreachBB, Shape.CoroSuspends.size());
9898 Shape.ResumeSwitch = Switch;
228228 Builder.SetInsertPoint(OldSwitchBB->getTerminator());
229229 auto *GepIndex = Builder.CreateConstInBoundsGEP2_32(Shape.FrameTy, FramePtr,
230230 0, 0, "ResumeFn.addr");
231 auto *Load = Builder.CreateLoad(GepIndex);
231 auto *Load = Builder.CreateLoad(
232 Shape.FrameTy->getElementType(coro::Shape::ResumeField), GepIndex);
232233 auto *NullPtr =
233234 ConstantPointerNull::get(cast(Load->getType()));
234235 auto *Cond = Builder.CreateICmpEQ(Load, NullPtr);
262262 Value *Idx = GetElementPtrInst::Create(
263263 STy, *AI, Idxs, (*AI)->getName() + "." + Twine(i), Call);
264264 // TODO: Tell AA about the new values?
265 Args.push_back(new LoadInst(Idx, Idx->getName() + ".val", Call));
265 Args.push_back(new LoadInst(STy->getElementType(i), Idx,
266 Idx->getName() + ".val", Call));
266267 ArgAttrVec.push_back(AttributeSet());
267268 }
268269 } else if (!I->use_empty()) {
298299 }
299300 // Since we're replacing a load make sure we take the alignment
300301 // of the previous load.
301 LoadInst *newLoad = new LoadInst(V, V->getName() + ".val", Call);
302 LoadInst *newLoad =
303 new LoadInst(OrigLoad->getType(), V, V->getName() + ".val", Call);
302304 newLoad->setAlignment(OrigLoad->getAlignment());
303305 // Transfer the AA info too.
304306 AAMDNodes AAInfo;
904904
905905 // Replace the cmp X, 0 with a use of the bool value.
906906 // Sink the load to where the compare was, if atomic rules allow us to.
907 Value *LV = new LoadInst(InitBool, InitBool->getName()+".val", false, 0,
907 Value *LV = new LoadInst(InitBool->getValueType(), InitBool,
908 InitBool->getName() + ".val", false, 0,
908909 LI->getOrdering(), LI->getSyncScopeID(),
909 LI->isUnordered() ? (Instruction*)ICI : LI);
910 LI->isUnordered() ? (Instruction *)ICI : LI);
910911 InitBoolUsed = true;
911912 switch (ICI->getPredicate()) {
912913 default: llvm_unreachable("Unknown ICmp Predicate!");
10391040 }
10401041
10411042 // Insert a load from the global, and use it instead of the malloc.
1042 Value *NL = new LoadInst(GV, GV->getName()+".val", InsertPt);
1043 Value *NL =
1044 new LoadInst(GV->getValueType(), GV, GV->getName() + ".val", InsertPt);
10431045 U->replaceUsesOfWith(Alloc, NL);
10441046 }
10451047 }
11621164 if (LoadInst *LI = dyn_cast(V)) {
11631165 // This is a scalarized version of the load from the global. Just create
11641166 // a new Load of the scalarized global.
1165 Result = new LoadInst(GetHeapSROAValue(LI->getOperand(0), FieldNo,
1166 InsertedScalarizedValues,
1167 PHIsToRewrite),
1168 LI->getName()+".f"+Twine(FieldNo), LI);
1167 Value *V = GetHeapSROAValue(LI->getOperand(0), FieldNo,
1168 InsertedScalarizedValues, PHIsToRewrite);
1169 Result = new LoadInst(V->getType()->getPointerElementType(), V,
1170 LI->getName() + ".f" + Twine(FieldNo), LI);
11691171 } else {
11701172 PHINode *PN = cast(V);
11711173 // PN's type is pointer to struct. Make a new PHI of pointer to struct
13551357 // Within the NullPtrBlock, we need to emit a comparison and branch for each
13561358 // pointer, because some may be null while others are not.
13571359 for (unsigned i = 0, e = FieldGlobals.size(); i != e; ++i) {
1358 Value *GVVal = new LoadInst(FieldGlobals[i], "tmp", NullPtrBlock);
1360 Value *GVVal =
1361 new LoadInst(cast(FieldGlobals[i])->getValueType(),
1362 FieldGlobals[i], "tmp", NullPtrBlock);
13591363 Value *Cmp = new ICmpInst(*NullPtrBlock, ICmpInst::ICMP_NE, GVVal,
13601364 Constant::getNullValue(GVVal->getType()));
13611365 BasicBlock *FreeBlock = BasicBlock::Create(Cmp->getContext(), "free_it",
16991703 if (LoadInst *LI = dyn_cast(StoredVal)) {
17001704 assert(LI->getOperand(0) == GV && "Not a copy!");
17011705 // Insert a new load, to preserve the saved value.
1702 StoreVal = new LoadInst(NewGV, LI->getName()+".b", false, 0,
1706 StoreVal = new LoadInst(NewGV->getValueType(), NewGV,
1707 LI->getName() + ".b", false, 0,
17031708 LI->getOrdering(), LI->getSyncScopeID(), LI);
17041709 } else {
17051710 assert((isa(StoredVal) || isa(StoredVal)) &&
17151720 } else {
17161721 // Change the load into a load of bool then a select.
17171722 LoadInst *LI = cast(UI);
1718 LoadInst *NLI = new LoadInst(NewGV, LI->getName()+".b", false, 0,
1719 LI->getOrdering(), LI->getSyncScopeID(), LI);
1723 LoadInst *NLI =
1724 new LoadInst(NewGV->getValueType(), NewGV, LI->getName() + ".b",
1725 false, 0, LI->getOrdering(), LI->getSyncScopeID(), LI);
17201726 Instruction *NSI;
17211727 if (IsOneZero)
17221728 NSI = new ZExtInst(NLI, LI->getType(), "", LI);
617617 }
618618
619619 Value *ByteAddr = B.CreateGEP(Int8Ty, ByteArray, BitOffset);
620 Value *Byte = B.CreateLoad(ByteAddr);
620 Value *Byte = B.CreateLoad(Int8Ty, ByteAddr);
621621
622622 Value *ByteAndMask =
623623 B.CreateAnd(Byte, ConstantExpr::getPtrToInt(TIL.BitMask, Int8Ty));
11821182 Value *Addr =
11831183 B.CreateGEP(Int8Ty, B.CreateBitCast(Call.VTable, Int8PtrTy), Byte);
11841184 if (RetType->getBitWidth() == 1) {
1185 Value *Bits = B.CreateLoad(Addr);
1185 Value *Bits = B.CreateLoad(Int8Ty, Addr);
11861186 Value *BitsAndBit = B.CreateAnd(Bits, Bit);
11871187 auto IsBitSet = B.CreateICmpNE(BitsAndBit, ConstantInt::get(Int8Ty, 0));
11881188 Call.replaceAndErase("virtual-const-prop-1-bit", FnName, RemarksEnabled,
170170
171171 Value *Src = Builder.CreateBitCast(MI->getArgOperand(1), NewSrcPtrTy);
172172 Value *Dest = Builder.CreateBitCast(MI->getArgOperand(0), NewDstPtrTy);
173 LoadInst *L = Builder.CreateLoad(Src);
173 LoadInst *L = Builder.CreateLoad(IntType, Src);
174174 // Alignment from the mem intrinsic will be better, so use it.
175175 L->setAlignment(CopySrcAlign);
176176 if (CopyMD)
11811181 if (maskIsAllOneOrUndef(II.getArgOperand(2))) {
11821182 Value *LoadPtr = II.getArgOperand(0);
11831183 unsigned Alignment = cast(II.getArgOperand(1))->getZExtValue();
1184 return Builder.CreateAlignedLoad(LoadPtr, Alignment, "unmaskedload");
1184 return Builder.CreateAlignedLoad(II.getType(), LoadPtr, Alignment,
1185 "unmaskedload");
11851186 }
11861187
11871188 return nullptr;
14981499
14991500 auto *BCastInst = Builder.CreateBitCast(II.getArgOperand(0),
15001501 PointerType::get(II.getType(), 0));
1501 return Builder.CreateAlignedLoad(BCastInst, Alignment);
1502 return Builder.CreateAlignedLoad(II.getType(), BCastInst, Alignment);
15021503 }
15031504
15041505 // Returns true iff the 2 intrinsics have the same operands, limiting the
22992300 &DT) >= 16) {
23002301 Value *Ptr = Builder.CreateBitCast(II->getArgOperand(0),
23012302 PointerType::getUnqual(II->getType()));
2302 return new LoadInst(Ptr);
2303 return new LoadInst(II->getType(), Ptr);
23032304 }
23042305 break;
23052306 case Intrinsic::ppc_vsx_lxvw4x:
23072308 // Turn PPC VSX loads into normal loads.
23082309 Value *Ptr = Builder.CreateBitCast(II->getArgOperand(0),
23092310 PointerType::getUnqual(II->getType()));
2310 return new LoadInst(Ptr, Twine(""), false, 1);
2311 return new LoadInst(II->getType(), Ptr, Twine(""), false, 1);
23112312 }
23122313 case Intrinsic::ppc_altivec_stvx:
23132314 case Intrinsic::ppc_altivec_stvxl:
23352336 II->getType()->getVectorNumElements());
23362337 Value *Ptr = Builder.CreateBitCast(II->getArgOperand(0),
23372338 PointerType::getUnqual(VTy));
2338 Value *Load = Builder.CreateLoad(Ptr);
2339 Value *Load = Builder.CreateLoad(VTy, Ptr);
23392340 return new FPExtInst(Load, II->getType());
23402341 }
23412342 break;
23452346 &DT) >= 32) {
23462347 Value *Ptr = Builder.CreateBitCast(II->getArgOperand(0),
23472348 PointerType::getUnqual(II->getType()));
2348 return new LoadInst(Ptr);
2349 return new LoadInst(II->getType(), Ptr);
23492350 }
23502351 break;
23512352 case Intrinsic::ppc_qpx_qvstfs:
297297 if (auto *LT = dyn_cast(I)) {
298298 auto *V = getReplacement(LT->getPointerOperand());
299299 assert(V && "Operand not replaced");
300 auto *NewI = new LoadInst(V);
300 auto *NewI = new LoadInst(I->getType(), V);
301301 NewI->takeName(LT);
302302 IC.InsertNewInstWith(NewI, *LT);
303303 IC.replaceInstUsesWith(*LT, NewI);
464464 NewPtr = IC.Builder.CreateBitCast(Ptr, NewTy->getPointerTo(AS));
465465
466466 LoadInst *NewLoad = IC.Builder.CreateAlignedLoad(
467 NewPtr, LI.getAlignment(), LI.isVolatile(), LI.getName() + Suffix);
467 NewTy, NewPtr, LI.getAlignment(), LI.isVolatile(), LI.getName() + Suffix);
468468 NewLoad->setAtomic(LI.getOrdering(), LI.getSyncScopeID());
469469 MDBuilder MDB(NewLoad->getContext());
470470 for (const auto &MDPair : MD) {
723723 auto *Ptr = IC.Builder.CreateInBoundsGEP(ST, Addr, makeArrayRef(Indices),
724724 Name + ".elt");
725725 auto EltAlign = MinAlign(Align, SL->getElementOffset(i));
726 auto *L = IC.Builder.CreateAlignedLoad(Ptr, EltAlign, Name + ".unpack");
726 auto *L = IC.Builder.CreateAlignedLoad(ST->getElementType(i), Ptr,
727 EltAlign, Name + ".unpack");
727728 // Propagate AA metadata. It'll still be valid on the narrowed load.
728729 AAMDNodes AAMD;
729730 LI.getAAMetadata(AAMD);
773774 };
774775 auto *Ptr = IC.Builder.CreateInBoundsGEP(AT, Addr, makeArrayRef(Indices),
775776 Name + ".elt");
776 auto *L = IC.Builder.CreateAlignedLoad(Ptr, MinAlign(Align, Offset),
777 Name + ".unpack");
777 auto *L = IC.Builder.CreateAlignedLoad(
778 AT->getElementType(), Ptr, MinAlign(Align, Offset), Name + ".unpack");
778779 AAMDNodes AAMD;
779780 LI.getAAMetadata(AAMD);
780781 L->setAAMetadata(AAMD);
10641065 unsigned Align = LI.getAlignment();
10651066 if (isSafeToLoadUnconditionally(SI->getOperand(1), Align, DL, SI) &&
10661067 isSafeToLoadUnconditionally(SI->getOperand(2), Align, DL, SI)) {
1067 LoadInst *V1 = Builder.CreateLoad(SI->getOperand(1),
1068 SI->getOperand(1)->getName()+".val");
1069 LoadInst *V2 = Builder.CreateLoad(SI->getOperand(2),
1070 SI->getOperand(2)->getName()+".val");
1068 LoadInst *V1 =
1069 Builder.CreateLoad(LI.getType(), SI->getOperand(1),
1070 SI->getOperand(1)->getName() + ".val");
1071 LoadInst *V2 =
1072 Builder.CreateLoad(LI.getType(), SI->getOperand(2),
1073 SI->getOperand(2)->getName() + ".val");
10711074 assert(LI.isUnordered() && "implied by above");
10721075 V1->setAlignment(Align);
10731076 V1->setAtomic(LI.getOrdering(), LI.getSyncScopeID());
594594
595595 Value *InVal = FirstLI->getOperand(0);
596596 NewPN->addIncoming(InVal, PN.getIncomingBlock(0));
597 LoadInst *NewLI = new LoadInst(NewPN, "", isVolatile, LoadAlignment);
597 LoadInst *NewLI =
598 new LoadInst(FirstLI->getType(), NewPN, "", isVolatile, LoadAlignment);
598599
599600 unsigned KnownIDs[] = {
600601 LLVMContext::MD_tbaa,
26852685 Builder.SetInsertPoint(L);
26862686 Value *GEP = Builder.CreateInBoundsGEP(L->getType(),
26872687 L->getPointerOperand(), Indices);
2688 Instruction *NL = Builder.CreateLoad(GEP);
2688 Instruction *NL = Builder.CreateLoad(EV.getType(), GEP);
26892689 // Whatever aliasing information we had for the orignal load must also
26902690 // hold for the smaller load, so propagate the annotations.
26912691 AAMDNodes Nodes;
948948 DynamicAreaOffset);
949949 }
950950
951 IRB.CreateCall(AsanAllocasUnpoisonFunc,
952 {IRB.CreateLoad(DynamicAllocaLayout), DynamicAreaPtr});
951 IRB.CreateCall(
952 AsanAllocasUnpoisonFunc,
953 {IRB.CreateLoad(IntptrTy, DynamicAllocaLayout), DynamicAreaPtr});
953954 }
954955
955956 // Unpoison dynamic allocas redzones.
15511552 Value *ShadowPtr = memToShadow(AddrLong, IRB);
15521553 Value *CmpVal = Constant::getNullValue(ShadowTy);
15531554 Value *ShadowValue =
1554 IRB.CreateLoad(IRB.CreateIntToPtr(ShadowPtr, ShadowPtrTy));
1555 IRB.CreateLoad(ShadowTy, IRB.CreateIntToPtr(ShadowPtr, ShadowPtrTy));
15551556
15561557 Value *Cmp = IRB.CreateICmpNE(ShadowValue, CmpVal);
15571558 size_t Granularity = 1ULL << Mapping.Scale;
24432444 } else {
24442445 Value *GlobalDynamicAddress = F.getParent()->getOrInsertGlobal(
24452446 kAsanShadowMemoryDynamicAddress, IntptrTy);
2446 LocalDynamicShadow = IRB.CreateLoad(GlobalDynamicAddress);
2447 LocalDynamicShadow = IRB.CreateLoad(IntptrTy, GlobalDynamicAddress);
24472448 }
24482449 }
24492450
29472948 // void *LocalStackBase = (FakeStack) ? FakeStack : alloca(LocalStackSize);
29482949 Constant *OptionDetectUseAfterReturn = F.getParent()->getOrInsertGlobal(
29492950 kAsanOptionDetectUseAfterReturn, IRB.getInt32Ty());
2950 Value *UseAfterReturnIsEnabled =
2951 IRB.CreateICmpNE(IRB.CreateLoad(OptionDetectUseAfterReturn),
2952 Constant::getNullValue(IRB.getInt32Ty()));
2951 Value *UseAfterReturnIsEnabled = IRB.CreateICmpNE(
2952 IRB.CreateLoad(IRB.getInt32Ty(), OptionDetectUseAfterReturn),
2953 Constant::getNullValue(IRB.getInt32Ty()));
29532954 Instruction *Term =
29542955 SplitBlockAndInsertIfThen(UseAfterReturnIsEnabled, InsBefore, false);
29552956 IRBuilder<> IRBIf(Term);
30833084 FakeStack,
30843085 ConstantInt::get(IntptrTy, ClassSize - ASan.LongSize / 8));
30853086 Value *SavedFlagPtr = IRBPoison.CreateLoad(
3086 IRBPoison.CreateIntToPtr(SavedFlagPtrPtr, IntptrPtrTy));
3087 IntptrTy, IRBPoison.CreateIntToPtr(SavedFlagPtrPtr, IntptrPtrTy));
30873088 IRBPoison.CreateStore(
30883089 Constant::getNullValue(IRBPoison.getInt8Ty()),
30893090 IRBPoison.CreateIntToPtr(SavedFlagPtr, IRBPoison.getInt8PtrTy()));
10321032 DFS.ArgTLS ? &*F->getEntryBlock().begin()
10331033 : cast(ArgTLSPtr)->getNextNode();
10341034 IRBuilder<> IRB(ArgTLSPos);
1035 Shadow = IRB.CreateLoad(getArgTLS(A->getArgNo(), ArgTLSPos));
1035 Shadow =
1036 IRB.CreateLoad(DFS.ShadowTy, getArgTLS(A->getArgNo(), ArgTLSPos));
10361037 break;
10371038 }
10381039 case DataFlowSanitizer::IA_Args: {
11821183 const auto i = AllocaShadowMap.find(AI);
11831184 if (i != AllocaShadowMap.end()) {
11841185 IRBuilder<> IRB(Pos);
1185 return IRB.CreateLoad(i->second);
1186 return IRB.CreateLoad(DFS.ShadowTy, i->second);
11861187 }
11871188 }
11881189
12071208 case 0:
12081209 return DFS.ZeroShadow;
12091210 case 1: {
1210 LoadInst *LI = new LoadInst(ShadowAddr, "", Pos);
1211 LoadInst *LI = new LoadInst(DFS.ShadowTy, ShadowAddr, "", Pos);
12111212 LI->setAlignment(ShadowAlign);
12121213 return LI;
12131214 }
12151216 IRBuilder<> IRB(Pos);
12161217 Value *ShadowAddr1 = IRB.CreateGEP(DFS.ShadowTy, ShadowAddr,
12171218 ConstantInt::get(DFS.IntptrTy, 1));
1218 return combineShadows(IRB.CreateAlignedLoad(ShadowAddr, ShadowAlign),
1219 IRB.CreateAlignedLoad(ShadowAddr1, ShadowAlign), Pos);
1219 return combineShadows(
1220 IRB.CreateAlignedLoad(DFS.ShadowTy, ShadowAddr, ShadowAlign),
1221 IRB.CreateAlignedLoad(DFS.ShadowTy, ShadowAddr1, ShadowAlign), Pos);
12201222 }
12211223 }
12221224 if (!AvoidNewBlocks && Size % (64 / DFS.ShadowWidth) == 0) {
12351237 IRBuilder<> IRB(Pos);
12361238 Value *WideAddr =
12371239 IRB.CreateBitCast(ShadowAddr, Type::getInt64PtrTy(*DFS.Ctx));
1238 Value *WideShadow = IRB.CreateAlignedLoad(WideAddr, ShadowAlign);
1240 Value *WideShadow =
1241 IRB.CreateAlignedLoad(IRB.getInt64Ty(), WideAddr, ShadowAlign);
12391242 Value *TruncShadow = IRB.CreateTrunc(WideShadow, DFS.ShadowTy);
12401243 Value *ShlShadow = IRB.CreateShl(WideShadow, DFS.ShadowWidth);
12411244 Value *ShrShadow = IRB.CreateLShr(WideShadow, 64 - DFS.ShadowWidth);
12681271 IRBuilder<> NextIRB(NextBB);
12691272 WideAddr = NextIRB.CreateGEP(Type::getInt64Ty(*DFS.Ctx), WideAddr,
12701273 ConstantInt::get(DFS.IntptrTy, 1));
1271 Value *NextWideShadow = NextIRB.CreateAlignedLoad(WideAddr, ShadowAlign);
1274 Value *NextWideShadow = NextIRB.CreateAlignedLoad(NextIRB.getInt64Ty(),
1275 WideAddr, ShadowAlign);
12721276 ShadowsEq = NextIRB.CreateICmpEQ(WideShadow, NextWideShadow);
12731277 LastBr->setSuccessor(0, NextBB);
12741278 LastBr = NextIRB.CreateCondBr(ShadowsEq, FallbackBB, FallbackBB);
16451649 }
16461650
16471651 if (!FT->getReturnType()->isVoidTy()) {
1648 LoadInst *LabelLoad = IRB.CreateLoad(DFSF.LabelReturnAlloca);
1652 LoadInst *LabelLoad =
1653 IRB.CreateLoad(DFSF.DFS.ShadowTy, DFSF.LabelReturnAlloca);
16491654 DFSF.setShadow(CustomCI, LabelLoad);
16501655 }
16511656
16831688
16841689 if (DFSF.DFS.getInstrumentedABI() == DataFlowSanitizer::IA_TLS) {
16851690 IRBuilder<> NextIRB(Next);
1686 LoadInst *LI = NextIRB.CreateLoad(DFSF.getRetvalTLS());
1691 LoadInst *LI = NextIRB.CreateLoad(DFSF.DFS.ShadowTy, DFSF.getRetvalTLS());
16871692 DFSF.SkipInsts.insert(LI);
16881693 DFSF.setShadow(CS.getInstruction(), LI);
16891694 DFSF.NonZeroChecks.push_back(LI);
789789 ConstantExpr::getGetElementPtr(
790790 ArrayType::get(IRB.getInt64Ty(), getStructCounterSize(StructTy)),
791791 CounterArray, Indices);
792 Value *Load = IRB.CreateLoad(Counter);
792 Value *Load = IRB.CreateLoad(IRB.getInt64Ty(), Counter);
793793 IRB.CreateStore(IRB.CreateAdd(Load, ConstantInt::get(IRB.getInt64Ty(), 1)),
794794 Counter);
795795 return true;
874874 // memory access, if they are not already set.
875875 Value *ValueMask = ConstantInt::get(ShadowTy, 0x81); // 10000001B
876876
877 Value *OldValue = IRB.CreateLoad(IRB.CreateIntToPtr(ShadowPtr, ShadowPtrTy));
877 Value *OldValue =
878 IRB.CreateLoad(ShadowTy, IRB.CreateIntToPtr(ShadowPtr, ShadowPtrTy));
878879 // The AND and CMP will be turned into a TEST instruction by the compiler.
879880 Value *Cmp = IRB.CreateICmpNE(IRB.CreateAnd(OldValue, ValueMask), ValueMask);
880881 Instruction *CmpTerm = SplitBlockAndInsertIfThen(Cmp, I, false);
816816
817817 // Skip phis, landingpads.
818818 IRBuilder<> Builder(&*BB.getFirstInsertionPt());
819 Value *Count = Builder.CreateLoad(Phi);
819 Value *Count = Builder.CreateLoad(Builder.getInt64Ty(), Phi);
820820 Count = Builder.CreateAdd(Count, Builder.getInt64(1));
821821 Builder.CreateStore(Count, Phi);
822822
827827 const unsigned Edge = It->second;
828828 Value *Counter =
829829 Builder.CreateConstInBoundsGEP2_64(Counters, 0, Edge);
830 Value *Count = Builder.CreateLoad(Counter);
830 Value *Count = Builder.CreateLoad(Builder.getInt64Ty(), Counter);
831831 Count = Builder.CreateAdd(Count, Builder.getInt64(1));
832832 Builder.CreateStore(Count, Counter);
833833 }
10881088 auto *StartFileCallArgsPtr = Builder.CreateStructGEP(FileInfoPtr, 0);
10891089 auto *StartFileCall = Builder.CreateCall(
10901090 StartFile,
1091 {Builder.CreateLoad(Builder.CreateStructGEP(StartFileCallArgsPtr, 0)),
1092 Builder.CreateLoad(Builder.CreateStructGEP(StartFileCallArgsPtr, 1)),
1093 Builder.CreateLoad(Builder.CreateStructGEP(StartFileCallArgsPtr, 2))});
1091 {Builder.CreateLoad(StartFileCallArgsTy->getElementType(0),
1092 Builder.CreateStructGEP(StartFileCallArgsPtr, 0)),
1093 Builder.CreateLoad(StartFileCallArgsTy->getElementType(1),
1094 Builder.CreateStructGEP(StartFileCallArgsPtr, 1)),
1095 Builder.CreateLoad(StartFileCallArgsTy->getElementType(2),
1096 Builder.CreateStructGEP(StartFileCallArgsPtr, 2))});
10941097 if (auto AK = TLI->getExtAttrForI32Param(false))
10951098 StartFileCall->addParamAttr(2, AK);
1096 auto *NumCounters =
1097 Builder.CreateLoad(Builder.CreateStructGEP(FileInfoPtr, 1));
1098 auto *EmitFunctionCallArgsArray =
1099 Builder.CreateLoad(Builder.CreateStructGEP(FileInfoPtr, 2));
1100 auto *EmitArcsCallArgsArray =
1101 Builder.CreateLoad(Builder.CreateStructGEP(FileInfoPtr, 3));
1099 auto *NumCounters = Builder.CreateLoad(
1100 FileInfoTy->getElementType(1), Builder.CreateStructGEP(FileInfoPtr, 1));
1101 auto *EmitFunctionCallArgsArray = Builder.CreateLoad(
1102 FileInfoTy->getElementType(2), Builder.CreateStructGEP(FileInfoPtr, 2));
1103 auto *EmitArcsCallArgsArray = Builder.CreateLoad(
1104 FileInfoTy->getElementType(3), Builder.CreateStructGEP(FileInfoPtr, 3));
11021105 auto *EnterCounterLoopCond =
11031106 Builder.CreateICmpSLT(Builder.getInt32(0), NumCounters);
11041107 Builder.CreateCondBr(EnterCounterLoopCond, CounterLoopHeader, FileLoopLatch);
11101113 Builder.CreateInBoundsGEP(EmitFunctionCallArgsArray, {JV});
11111114 auto *EmitFunctionCall = Builder.CreateCall(
11121115 EmitFunction,
1113 {Builder.CreateLoad(Builder.CreateStructGEP(EmitFunctionCallArgsPtr, 0)),
1114 Builder.CreateLoad(Builder.CreateStructGEP(EmitFunctionCallArgsPtr, 1)),
1115 Builder.CreateLoad(Builder.CreateStructGEP(EmitFunctionCallArgsPtr, 2)),
1116 Builder.CreateLoad(Builder.CreateStructGEP(EmitFunctionCallArgsPtr, 3)),
1116 {Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(0),
1117 Builder.CreateStructGEP(EmitFunctionCallArgsPtr, 0)),
1118 Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(1),
1119 Builder.CreateStructGEP(EmitFunctionCallArgsPtr, 1)),
1120 Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(2),
1121 Builder.CreateStructGEP(EmitFunctionCallArgsPtr, 2)),
1122 Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(3),
1123 Builder.CreateStructGEP(EmitFunctionCallArgsPtr, 3)),
11171124 Builder.CreateLoad(
1125 EmitFunctionCallArgsTy->getElementType(4),
11181126 Builder.CreateStructGEP(EmitFunctionCallArgsPtr, 4))});
11191127 if (auto AK = TLI->getExtAttrForI32Param(false)) {
11201128 EmitFunctionCall->addParamAttr(0, AK);
11261134 Builder.CreateInBoundsGEP(EmitArcsCallArgsArray, {JV});
11271135 auto *EmitArcsCall = Builder.CreateCall(
11281136 EmitArcs,
1129 {Builder.CreateLoad(Builder.CreateStructGEP(EmitArcsCallArgsPtr, 0)),
1130 Builder.CreateLoad(Builder.CreateStructGEP(EmitArcsCallArgsPtr, 1))});
1137 {Builder.CreateLoad(EmitArcsCallArgsTy->getElementType(0),
1138 Builder.CreateStructGEP(EmitArcsCallArgsPtr, 0)),
1139 Builder.CreateLoad(EmitArcsCallArgsTy->getElementType(1),
1140 Builder.CreateStructGEP(EmitArcsCallArgsPtr, 1))});
11311141 if (auto AK = TLI->getExtAttrForI32Param(false))
11321142 EmitArcsCall->addParamAttr(0, AK);
11331143 auto *NextJV = Builder.CreateAdd(JV, Builder.getInt32(1));
427427 Value *GlobalDynamicAddress =
428428 IRB.GetInsertBlock()->getParent()->getParent()->getOrInsertGlobal(
429429 kHwasanShadowMemoryDynamicAddress, Int8PtrTy);
430 return IRB.CreateLoad(GlobalDynamicAddress);
430 return IRB.CreateLoad(Int8PtrTy, GlobalDynamicAddress);
431431 }
432432 }
433433
556556 IRB.getInt8Ty());
557557 Value *AddrLong = untagPointer(IRB, PtrLong);
558558 Value *Shadow = memToShadow(AddrLong, IRB);
559 Value *MemTag = IRB.CreateLoad(Shadow);
559 Value *MemTag = IRB.CreateLoad(Int8Ty, Shadow);
560560 Value *TagMismatch = IRB.CreateICmpNE(PtrTag, MemTag);
561561
562562 int matchAllTag = ClMatchAllTag.getNumOccurrences() > 0 ?
840840 Value *SlotPtr = getHwasanThreadSlotPtr(IRB, IntptrTy);
841841 assert(SlotPtr);
842842
843 Instruction *ThreadLong = IRB.CreateLoad(SlotPtr);
843 Instruction *ThreadLong = IRB.CreateLoad(IntptrTy, SlotPtr);
844844
845845 Function *F = IRB.GetInsertBlock()->getParent();
846846 if (F->getFnAttribute("hwasan-abi").getValueAsString() == "interceptor") {
854854 // FIXME: This should call a new runtime function with a custom calling
855855 // convention to avoid needing to spill all arguments here.
856856 IRB.CreateCall(HwasanThreadEnterFunc);
857 LoadInst *ReloadThreadLong = IRB.CreateLoad(SlotPtr);
857 LoadInst *ReloadThreadLong = IRB.CreateLoad(IntptrTy, SlotPtr);
858858
859859 IRB.SetInsertPoint(&*Br->getSuccessor(0)->begin());
860860 PHINode *ThreadLongPhi = IRB.CreatePHI(IntptrTy, 2);
194194 // block.
195195 Value *LiveInValue = SSA.GetValueInMiddleOfBlock(ExitBlock);
196196 Value *Addr = cast(Store)->getPointerOperand();
197 Type *Ty = LiveInValue->getType();
197198 IRBuilder<> Builder(InsertPos);
198199 if (AtomicCounterUpdatePromoted)
199200 // automic update currently can only be promoted across the current
201202 Builder.CreateAtomicRMW(AtomicRMWInst::Add, Addr, LiveInValue,
202203 AtomicOrdering::SequentiallyConsistent);
203204 else {
204 LoadInst *OldVal = Builder.CreateLoad(Addr, "pgocount.promoted");
205 LoadInst *OldVal = Builder.CreateLoad(Ty, Addr, "pgocount.promoted");
205206 auto *NewVal = Builder.CreateAdd(OldVal, LiveInValue);
206207 auto *NewStore = Builder.CreateStore(NewVal, Addr);
207208
602603 Builder.CreateAtomicRMW(AtomicRMWInst::Add, Addr, Inc->getStep(),
603604 AtomicOrdering::Monotonic);
604605 } else {
605 Value *Load = Builder.CreateLoad(Addr, "pgocount");
606 Value *IncStep = Inc->getStep();
607 Value *Load = Builder.CreateLoad(IncStep->getType(), Addr, "pgocount");
606608 auto *Count = Builder.CreateAdd(Load, Inc->getStep());
607609 auto *Store = Builder.CreateStore(Count, Addr);
608610 if (isCounterPromotionEnabled())
949951 User->setComdat(M->getOrInsertComdat(User->getName()));
950952
951953 IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", User));
952 auto *Load = IRB.CreateLoad(Var);
954 auto *Load = IRB.CreateLoad(Int32Ty, Var);
953955 IRB.CreateRet(Load);
954956
955957 // Mark the user variable as used so that it isn't stripped out.
14001400 IRB.CreateAnd(OriginLong, ConstantInt::get(MS.IntptrTy, ~Mask));
14011401 }
14021402 OriginPtr =
1403 IRB.CreateIntToPtr(OriginLong, PointerType::get(IRB.getInt32Ty(), 0));
1403 IRB.CreateIntToPtr(OriginLong, PointerType::get(MS.OriginTy, 0));
14041404 }
14051405 return std::make_pair(ShadowPtr, OriginPtr);
14061406 }
16171617 // ParamTLS overflow.
16181618 *ShadowPtr = getCleanShadow(V);
16191619 } else {
1620 *ShadowPtr =
1621 EntryIRB.CreateAlignedLoad(Base, kShadowTLSAlignment);
1620 *ShadowPtr = EntryIRB.CreateAlignedLoad(getShadowTy(&FArg), Base,
1621 kShadowTLSAlignment);
16221622 }
16231623 }
16241624 LLVM_DEBUG(dbgs()
16261626 if (MS.TrackOrigins && !Overflow) {
16271627 Value *OriginPtr =
16281628 getOriginPtrForArgument(&FArg, EntryIRB, ArgOffset);
1629 setOrigin(A, EntryIRB.CreateLoad(OriginPtr));
1629 setOrigin(A, EntryIRB.CreateLoad(MS.OriginTy, OriginPtr));
16301630 } else {
16311631 setOrigin(A, getCleanOrigin());
16321632 }
17571757 if (PropagateShadow) {
17581758 std::tie(ShadowPtr, OriginPtr) =
17591759 getShadowOriginPtr(Addr, IRB, ShadowTy, Alignment, /*isStore*/ false);
1760 setShadow(&I, IRB.CreateAlignedLoad(ShadowPtr, Alignment, "_msld"));
1760 setShadow(&I,
1761 IRB.CreateAlignedLoad(ShadowTy, ShadowPtr, Alignment, "_msld"));
17611762 } else {
17621763 setShadow(&I, getCleanShadow(&I));
17631764 }
17711772 if (MS.TrackOrigins) {
17721773 if (PropagateShadow) {
17731774 unsigned OriginAlignment = std::max(kMinOriginAlignment, Alignment);
1774 setOrigin(&I, IRB.CreateAlignedLoad(OriginPtr, OriginAlignment));
1775 setOrigin(
1776 &I, IRB.CreateAlignedLoad(MS.OriginTy, OriginPtr, OriginAlignment));
17751777 } else {
17761778 setOrigin(&I, getCleanOrigin());
17771779 }
24512453 unsigned Alignment = 1;
24522454 std::tie(ShadowPtr, OriginPtr) =
24532455 getShadowOriginPtr(Addr, IRB, ShadowTy, Alignment, /*isStore*/ false);
2454 setShadow(&I, IRB.CreateAlignedLoad(ShadowPtr, Alignment, "_msld"));
2456 setShadow(&I,
2457 IRB.CreateAlignedLoad(ShadowTy, ShadowPtr, Alignment, "_msld"));
24552458 } else {
24562459 setShadow(&I, getCleanShadow(&I));
24572460 }
24612464
24622465 if (MS.TrackOrigins) {
24632466 if (PropagateShadow)
2464 setOrigin(&I, IRB.CreateLoad(OriginPtr));
2467 setOrigin(&I, IRB.CreateLoad(MS.OriginTy, OriginPtr));
24652468 else
24662469 setOrigin(&I, getCleanOrigin());
24672470 }
28442847 if (ClCheckAccessAddress)
28452848 insertShadowCheck(Addr, &I);
28462849
2847 Value *Shadow = IRB.CreateAlignedLoad(ShadowPtr, Alignment, "_ldmxcsr");
2848 Value *Origin =
2849 MS.TrackOrigins ? IRB.CreateLoad(OriginPtr) : getCleanOrigin();
2850 Value *Shadow = IRB.CreateAlignedLoad(Ty, ShadowPtr, Alignment, "_ldmxcsr");
2851 Value *Origin = MS.TrackOrigins ? IRB.CreateLoad(MS.OriginTy, OriginPtr)
2852 : getCleanOrigin();
28502853 insertShadowCheck(Shadow, Origin, &I);
28512854 }
28522855
29202923
29212924 Value *Origin = IRB.CreateSelect(
29222925 IRB.CreateICmpNE(Acc, Constant::getNullValue(Acc->getType())),
2923 getOrigin(PassThru), IRB.CreateLoad(OriginPtr));
2926 getOrigin(PassThru), IRB.CreateLoad(MS.OriginTy, OriginPtr));
29242927
29252928 setOrigin(&I, Origin);
29262929 } else {
32833286 "Could not find insertion point for retval shadow load");
32843287 }
32853288 IRBuilder<> IRBAfter(&*NextInsn);
3286 Value *RetvalShadow =
3287 IRBAfter.CreateAlignedLoad(getShadowPtrForRetval(&I, IRBAfter),
3288 kShadowTLSAlignment, "_msret");
3289 Value *RetvalShadow = IRBAfter.CreateAlignedLoad(
3290 getShadowTy(&I), getShadowPtrForRetval(&I, IRBAfter),
3291 kShadowTLSAlignment, "_msret");
32893292 setShadow(&I, RetvalShadow);
32903293 if (MS.TrackOrigins)
3291 setOrigin(&I, IRBAfter.CreateLoad(getOriginPtrForRetval(IRBAfter)));
3294 setOrigin(&I, IRBAfter.CreateLoad(MS.OriginTy,
3295 getOriginPtrForRetval(IRBAfter)));
32923296 }
32933297
32943298 bool isAMustTailRetVal(Value *RetVal) {
38363840 // If there is a va_start in this function, make a backup copy of
38373841 // va_arg_tls somewhere in the function entry block.
38383842 IRBuilder<> IRB(MSV.ActualFnStart->getFirstNonPHI());
3839 VAArgOverflowSize = IRB.CreateLoad(MS.VAArgOverflowSizeTLS);
3843 VAArgOverflowSize =
3844 IRB.CreateLoad(IRB.getInt64Ty(), MS.VAArgOverflowSizeTLS);
38403845 Value *CopySize =
38413846 IRB.CreateAdd(ConstantInt::get(MS.IntptrTy, AMD64FpEndOffset),
38423847 VAArgOverflowSize);
38553860 IRBuilder<> IRB(OrigInst->getNextNode());
38563861 Value *VAListTag = OrigInst->getArgOperand(0);
38573862
3863 Type *RegSaveAreaPtrTy = Type::getInt64PtrTy(*MS.C);
38583864 Value *RegSaveAreaPtrPtr = IRB.CreateIntToPtr(
38593865 IRB.CreateAdd(IRB.CreatePtrToInt(VAListTag, MS.IntptrTy),
38603866 ConstantInt::get(MS.IntptrTy, 16)),
3861 PointerType::get(Type::getInt64PtrTy(*MS.C), 0));
3862 Value *RegSaveAreaPtr = IRB.CreateLoad(RegSaveAreaPtrPtr);
3867 PointerType::get(RegSaveAreaPtrTy, 0));
3868 Value *RegSaveAreaPtr =
3869 IRB.CreateLoad(RegSaveAreaPtrTy, RegSaveAreaPtrPtr);
38633870 Value *RegSaveAreaShadowPtr, *RegSaveAreaOriginPtr;
38643871 unsigned Alignment = 16;
38653872 std::tie(RegSaveAreaShadowPtr, RegSaveAreaOriginPtr) =
38703877 if (MS.TrackOrigins)
38713878 IRB.CreateMemCpy(RegSaveAreaOriginPtr, Alignment, VAArgTLSOriginCopy,
38723879 Alignment, AMD64FpEndOffset);
3880 Type *OverflowArgAreaPtrTy = Type::getInt64PtrTy(*MS.C);
38733881 Value *OverflowArgAreaPtrPtr = IRB.CreateIntToPtr(
38743882 IRB.CreateAdd(IRB.CreatePtrToInt(VAListTag, MS.IntptrTy),
38753883 ConstantInt::get(MS.IntptrTy, 8)),
3876 PointerType::get(Type::getInt64PtrTy(*MS.C), 0));
3877 Value *OverflowArgAreaPtr = IRB.CreateLoad(OverflowArgAreaPtrPtr);
3884 PointerType::get(OverflowArgAreaPtrTy, 0));
3885 Value *OverflowArgAreaPtr =
3886 IRB.CreateLoad(OverflowArgAreaPtrTy, OverflowArgAreaPtrPtr);
38783887 Value *OverflowArgAreaShadowPtr, *OverflowArgAreaOriginPtr;
38793888 std::tie(OverflowArgAreaShadowPtr, OverflowArgAreaOriginPtr) =
38803889 MSV.getShadowOriginPtr(OverflowArgAreaPtr, IRB, IRB.getInt8Ty(),
39763985 assert(!VAArgSize && !VAArgTLSCopy &&
39773986 "finalizeInstrumentation called twice");
39783987 IRBuilder<> IRB(MSV.ActualFnStart->getFirstNonPHI());
3979 VAArgSize = IRB.CreateLoad(MS.VAArgOverflowSizeTLS);
3988 VAArgSize = IRB.CreateLoad(IRB.getInt64Ty(), MS.VAArgOverflowSizeTLS);
39803989 Value *CopySize = IRB.CreateAdd(ConstantInt::get(MS.IntptrTy, 0),
39813990 VAArgSize);
39823991
39934002 CallInst *OrigInst = VAStartInstrumentationList[i];
39944003 IRBuilder<> IRB(OrigInst->getNextNode());
39954004 Value *VAListTag = OrigInst->getArgOperand(0);
4005 Type *RegSaveAreaPtrTy = Type::getInt64PtrTy(*MS.C);
39964006 Value *RegSaveAreaPtrPtr =
39974007 IRB.CreateIntToPtr(IRB.CreatePtrToInt(VAListTag, MS.IntptrTy),
3998 PointerType::get(Type::getInt64PtrTy(*MS.C), 0));
3999 Value *RegSaveAreaPtr = IRB.CreateLoad(RegSaveAreaPtrPtr);
4008 PointerType::get(RegSaveAreaPtrTy, 0));
4009 Value *RegSaveAreaPtr =
4010 IRB.CreateLoad(RegSaveAreaPtrTy, RegSaveAreaPtrPtr);
40004011 Value *RegSaveAreaShadowPtr, *RegSaveAreaOriginPtr;
40014012 unsigned Alignment = 8;
40024013 std::tie(RegSaveAreaShadowPtr, RegSaveAreaOriginPtr) =
41464157 IRB.CreateAdd(IRB.CreatePtrToInt(VAListTag, MS.IntptrTy),
41474158 ConstantInt::get(MS.IntptrTy, offset)),
41484159 Type::getInt64PtrTy(*MS.C));
4149 return IRB.CreateLoad(SaveAreaPtrPtr);
4160 return IRB.CreateLoad(Type::getInt64Ty(*MS.C), SaveAreaPtrPtr);
41504161 }
41514162
41524163 // Retrieve a va_list field of 'int' size.
41564167 IRB.CreateAdd(IRB.CreatePtrToInt(VAListTag, MS.IntptrTy),
41574168 ConstantInt::get(MS.IntptrTy, offset)),
41584169 Type::getInt32PtrTy(*MS.C));
4159 Value *SaveArea32 = IRB.CreateLoad(SaveAreaPtr);
4170 Value *SaveArea32 = IRB.CreateLoad(IRB.getInt32Ty(), SaveAreaPtr);
41604171 return IRB.CreateSExt(SaveArea32, MS.IntptrTy);
41614172 }
41624173
41674178 // If there is a va_start in this function, make a backup copy of
41684179 // va_arg_tls somewhere in the function entry block.
41694180 IRBuilder<> IRB(MSV.ActualFnStart->getFirstNonPHI());
4170 VAArgOverflowSize = IRB.CreateLoad(MS.VAArgOverflowSizeTLS);
4181 VAArgOverflowSize =
4182 IRB.CreateLoad(IRB.getInt64Ty(), MS.VAArgOverflowSizeTLS);
41714183 Value *CopySize =
41724184 IRB.CreateAdd(ConstantInt::get(MS.IntptrTy, AArch64VAEndOffset),
41734185 VAArgOverflowSize);
44104422 assert(!VAArgSize && !VAArgTLSCopy &&
44114423 "finalizeInstrumentation called twice");
44124424 IRBuilder<> IRB(MSV.ActualFnStart->getFirstNonPHI());
4413 VAArgSize = IRB.CreateLoad(MS.VAArgOverflowSizeTLS);
4425 VAArgSize = IRB.CreateLoad(IRB.getInt64Ty(), MS.VAArgOverflowSizeTLS);
44144426 Value *CopySize = IRB.CreateAdd(ConstantInt::get(MS.IntptrTy, 0),
44154427 VAArgSize);
44164428
44274439 CallInst *OrigInst = VAStartInstrumentationList[i];
44284440 IRBuilder<> IRB(OrigInst->getNextNode());
44294441 Value *VAListTag = OrigInst->getArgOperand(0);
4442 Type *RegSaveAreaPtrTy = Type::getInt64PtrTy(*MS.C);
44304443 Value *RegSaveAreaPtrPtr =
44314444 IRB.CreateIntToPtr(IRB.CreatePtrToInt(VAListTag, MS.IntptrTy),
4432 PointerType::get(Type::getInt64PtrTy(*MS.C), 0));
4433 Value *RegSaveAreaPtr = IRB.CreateLoad(RegSaveAreaPtrPtr);
4445 PointerType::get(RegSaveAreaPtrTy, 0));
4446 Value *RegSaveAreaPtr =
4447 IRB.CreateLoad(RegSaveAreaPtrTy, RegSaveAreaPtrPtr);
44344448 Value *RegSaveAreaShadowPtr, *RegSaveAreaOriginPtr;
44354449 unsigned Alignment = 8;
44364450 std::tie(RegSaveAreaShadowPtr, RegSaveAreaOriginPtr) =
821821 auto CounterPtr = IRB.CreateGEP(
822822 Function8bitCounterArray,
823823 {ConstantInt::get(IntptrTy, 0), ConstantInt::get(IntptrTy, Idx)});
824 auto Load = IRB.CreateLoad(CounterPtr);
824 auto Load = IRB.CreateLoad(Int8Ty, CounterPtr);
825825 auto Inc = IRB.CreateAdd(Load, ConstantInt::get(Int8Ty, 1));
826826 auto Store = IRB.CreateStore(Inc, CounterPtr);
827827 SetNoSanitizeMetadata(Load);
834834 auto FrameAddrPtr =
835835 IRB.CreateCall(GetFrameAddr, {Constant::getNullValue(Int32Ty)});
836836 auto FrameAddrInt = IRB.CreatePtrToInt(FrameAddrPtr, IntptrTy);
837 auto LowestStack = IRB.CreateLoad(SanCovLowestStack);
837 auto LowestStack = IRB.CreateLoad(IntptrTy, SanCovLowestStack);
838838 auto IsStackLower = IRB.CreateICmpULT(FrameAddrInt, LowestStack);
839839 auto ThenTerm = SplitBlockAndInsertIfThen(IsStackLower, &*IP, false);
840840 IRBuilder<> ThenIRB(ThenTerm);
12331233 BasicBlock *UnavailablePred = PredLoad.first;
12341234 Value *LoadPtr = PredLoad.second;
12351235
1236 auto *NewLoad = new LoadInst(LoadPtr, LI->getName()+".pre",
1237 LI->isVolatile(), LI->getAlignment(),
1238 LI->getOrdering(), LI->getSyncScopeID(),
1239 UnavailablePred->getTerminator());
1236 auto *NewLoad =
1237 new LoadInst(LI->getType(), LoadPtr, LI->getName() + ".pre",
1238 LI->isVolatile(), LI->getAlignment(), LI->getOrdering(),
1239 LI->getSyncScopeID(), UnavailablePred->getTerminator());
12401240 NewLoad->setDebugLoc(LI->getDebugLoc());
12411241
12421242 // Transfer the old load's AA tags to the new load.
14441444 if (UnavailablePred) {
14451445 assert(UnavailablePred->getTerminator()->getNumSuccessors() == 1 &&
14461446 "Can't handle critical edge here!");
1447 LoadInst *NewVal =
1448 new LoadInst(LoadedPtr->DoPHITranslation(LoadBB, UnavailablePred),
1449 LoadI->getName() + ".pr", false, LoadI->getAlignment(),
1450 LoadI->getOrdering(), LoadI->getSyncScopeID(),
1451 UnavailablePred->getTerminator());
1447 LoadInst *NewVal = new LoadInst(
1448 LoadI->getType(), LoadedPtr->DoPHITranslation(LoadBB, UnavailablePred),
1449 LoadI->getName() + ".pr", false, LoadI->getAlignment(),
1450 LoadI->getOrdering(), LoadI->getSyncScopeID(),
1451 UnavailablePred->getTerminator());
14521452 NewVal->setDebugLoc(LoadI->getDebugLoc());
14531453 if (AATags)
14541454 NewVal->setAAMetadata(AATags);
19461946 // Set up the preheader to have a definition of the value. It is the live-out
19471947 // value from the preheader that uses in the loop will use.
19481948 LoadInst *PreheaderLoad = new LoadInst(
1949 SomePtr, SomePtr->getName() + ".promoted", Preheader->getTerminator());
1949 SomePtr->getType()->getPointerElementType(), SomePtr,
1950 SomePtr->getName() + ".promoted", Preheader->getTerminator());
19501951 if (SawUnorderedAtomic)
19511952 PreheaderLoad->setOrdering(AtomicOrdering::Unordered);
19521953 PreheaderLoad->setAlignment(Alignment);
426426 auto *PH = L->getLoopPreheader();
427427 Value *InitialPtr = SEE.expandCodeFor(PtrSCEV->getStart(), Ptr->getType(),
428428 PH->getTerminator());
429 Value *Initial =
430 new LoadInst(InitialPtr, "load_initial", /* isVolatile */ false,
431 Cand.Load->getAlignment(), PH->getTerminator());
429 Value *Initial = new LoadInst(
430 Cand.Load->getType(), InitialPtr, "load_initial",
431 /* isVolatile */ false, Cand.Load->getAlignment(), PH->getTerminator());
432432
433433 PHINode *PHI = PHINode::Create(Initial->getType(), 2, "store_forwarded",
434434 &L->getHeader()->front());
2525 Value *Cmp = CXI->getCompareOperand();
2626 Value *Val = CXI->getNewValOperand();
2727
28 LoadInst *Orig = Builder.CreateLoad(Ptr);
28 LoadInst *Orig = Builder.CreateLoad(Val->getType(), Ptr);
2929 Value *Equal = Builder.CreateICmpEQ(Orig, Cmp);
3030 Value *Res = Builder.CreateSelect(Equal, Val, Orig);
3131 Builder.CreateStore(Res, Ptr);
4343 Value *Ptr = RMWI->getPointerOperand();
4444 Value *Val = RMWI->getValOperand();
4545
46 LoadInst *Orig = Builder.CreateLoad(Ptr);
46 LoadInst *Orig = Builder.CreateLoad(Val->getType(), Ptr);
4747 Value *Res = nullptr;
4848
4949 switch (RMWI->getOperation()) {
16351635 // for sanity checking.
16361636 static void
16371637 insertRelocationStores(iterator_range GCRelocs,
1638 DenseMapValue *> &AllocaMap,
1638 DenseMapAllocaInst *> &AllocaMap,
16391639 DenseSet &VisitedLiveValues) {
16401640 for (User *U : GCRelocs) {
16411641 GCRelocateInst *Relocate = dyn_cast(U);
16701670 // "insertRelocationStores" but works for rematerialized values.
16711671 static void insertRematerializationStores(
16721672 const RematerializedValueMapTy &RematerializedValues,
1673 DenseMapValue *> &AllocaMap,
1673 DenseMapAllocaInst *> &AllocaMap,
16741674 DenseSet &VisitedLiveValues) {
16751675 for (auto RematerializedValuePair: RematerializedValues) {
16761676 Instruction *RematerializedValue = RematerializedValuePair.first;
17031703 #endif
17041704
17051705 // TODO-PERF: change data structures, reserve
1706 DenseMapValue *> AllocaMap;
1706 DenseMapAllocaInst *> AllocaMap;
17071707 SmallVector PromotableAllocas;
17081708 // Used later to chack that we have enough allocas to store all values
17091709 std::size_t NumRematerializedValues = 0;
17731773 SmallVector ToClobber;
17741774 for (auto Pair : AllocaMap) {
17751775 Value *Def = Pair.first;
1776 AllocaInst *Alloca = cast(Pair.second);
1776 AllocaInst *Alloca = Pair.second;
17771777
17781778 // This value was relocated
17791779 if (VisitedLiveValues.count(Def)) {
18051805 // Update use with load allocas and add store for gc_relocated.
18061806 for (auto Pair : AllocaMap) {
18071807 Value *Def = Pair.first;
1808 Value *Alloca = Pair.second;
1808 AllocaInst *Alloca = Pair.second;
18091809
18101810 // We pre-record the uses of allocas so that we dont have to worry about
18111811 // later update that changes the user information..
18331833 PHINode *Phi = cast(Use);
18341834 for (unsigned i = 0; i < Phi->getNumIncomingValues(); i++) {
18351835 if (Def == Phi->getIncomingValue(i)) {
1836 LoadInst *Load = new LoadInst(
1837 Alloca, "", Phi->getIncomingBlock(i)->getTerminator());
1836 LoadInst *Load =
1837 new LoadInst(Alloca->getAllocatedType(), Alloca, "",
1838 Phi->getIncomingBlock(i)->getTerminator());
18381839 Phi->setIncomingValue(i, Load);
18391840 }
18401841 }
18411842 } else {
1842 LoadInst *Load = new LoadInst(Alloca, "", Use);
1843 LoadInst *Load =
1844 new LoadInst(Alloca->getAllocatedType(), Alloca, "", Use);
18431845 Use->replaceUsesOfWith(Def, Load);
18441846 }
18451847 }
12301230 static void speculatePHINodeLoads(PHINode &PN) {
12311231 LLVM_DEBUG(dbgs() << " original: " << PN << "\n");
12321232
1233 Type *LoadTy = cast(PN.getType())->getElementType();
1233 LoadInst *SomeLoad = cast(PN.user_back());
1234 Type *LoadTy = SomeLoad->getType();
12341235 IRBuilderTy PHIBuilder(&PN);
12351236 PHINode *NewPN = PHIBuilder.CreatePHI(LoadTy, PN.getNumIncomingValues(),
12361237 PN.getName() + ".sroa.speculated");
12371238
12381239 // Get the AA tags and alignment to use from one of the loads. It doesn't
12391240 // matter which one we get and if any differ.
1240 LoadInst *SomeLoad = cast(PN.user_back());
1241
12421241 AAMDNodes AATags;
12431242 SomeLoad->getAAMetadata(AATags);
12441243 unsigned Align = SomeLoad->getAlignment();
12691268 IRBuilderTy PredBuilder(TI);
12701269
12711270 LoadInst *Load = PredBuilder.CreateLoad(
1272 InVal, (PN.getName() + ".sroa.speculate.load." + Pred->getName()));
1271 LoadTy, InVal,
1272 (PN.getName() + ".sroa.speculate.load." + Pred->getName()));
12731273 ++NumLoadsSpeculated;
12741274 Load->setAlignment(Align);
12751275 if (AATags)
13291329 assert(LI->isSimple() && "We only speculate simple loads");
13301330
13311331 IRB.SetInsertPoint(LI);
1332 LoadInst *TL =
1333 IRB.CreateLoad(TV, LI->getName() + ".sroa.speculate.load.true");
1334 LoadInst *FL =
1335 IRB.CreateLoad(FV, LI->getName() + ".sroa.speculate.load.false");
1332 LoadInst *TL = IRB.CreateLoad(LI->getType(), TV,
1333 LI->getName() + ".sroa.speculate.load.true");
1334 LoadInst *FL = IRB.CreateLoad(LI->getType(), FV,
1335 LI->getName() + ".sroa.speculate.load.false");
13361336 NumLoadsSpeculated += 2;
13371337
13381338 // Transfer alignment and AA info if present.
24092409 unsigned EndIndex = getIndex(NewEndOffset);
24102410 assert(EndIndex > BeginIndex && "Empty vector!");
24112411
2412 Value *V = IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), "load");
2412 Value *V = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI,
2413 NewAI.getAlignment(), "load");
24132414 return extractVector(IRB, V, BeginIndex, EndIndex, "vec");
24142415 }
24152416
24162417 Value *rewriteIntegerLoad(LoadInst &LI) {
24172418 assert(IntTy && "We cannot insert an integer to the alloca");
24182419 assert(!LI.isVolatile());
2419 Value *V = IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), "load");
2420 Value *V = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI,
2421 NewAI.getAlignment(), "load");
24202422 V = convertValue(DL, IRB, V, IntTy);
24212423 assert(NewBeginOffset >= NewAllocaBeginOffset && "Out of bounds offset");
24222424 uint64_t Offset = NewBeginOffset - NewAllocaBeginOffset;
24602462 (canConvertValue(DL, NewAllocaTy, TargetTy) ||
24612463 (IsLoadPastEnd && NewAllocaTy->isIntegerTy() &&
24622464 TargetTy->isIntegerTy()))) {
2463 LoadInst *NewLI = IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(),
2465 LoadInst *NewLI = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI,
2466 NewAI.getAlignment(),
24642467 LI.isVolatile(), LI.getName());
24652468 if (AATags)
24662469 NewLI->setAAMetadata(AATags);
24962499 }
24972500 } else {
24982501 Type *LTy = TargetTy->getPointerTo(AS);
2499 LoadInst *NewLI = IRB.CreateAlignedLoad(getNewAllocaSlicePtr(IRB, LTy),
2500 getSliceAlign(TargetTy),
2501 LI.isVolatile(), LI.getName());
2502 LoadInst *NewLI = IRB.CreateAlignedLoad(
2503 TargetTy, getNewAllocaSlicePtr(IRB, LTy), getSliceAlign(TargetTy),
2504 LI.isVolatile(), LI.getName());
25022505 if (AATags)
25032506 NewLI->setAAMetadata(AATags);
25042507 if (LI.isVolatile())
25242527 // basis for the new value. This allows us to replace the uses of LI with
25252528 // the computed value, and then replace the placeholder with LI, leaving
25262529 // LI only used for this computation.
2527 Value *Placeholder =
2528 new LoadInst(UndefValue::get(LI.getType()->getPointerTo(AS)));
2530 Value *Placeholder = new LoadInst(
2531 LI.getType(), UndefValue::get(LI.getType()->getPointerTo(AS)));
25292532 V = insertInteger(DL, IRB, Placeholder, V, NewBeginOffset - BeginOffset,
25302533 "insert");
25312534 LI.replaceAllUsesWith(V);
25562559 V = convertValue(DL, IRB, V, SliceTy);
25572560
25582561 // Mix in the existing elements.
2559 Value *Old = IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), "load");
2562 Value *Old = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI,
2563 NewAI.getAlignment(), "load");
25602564 V = insertVector(IRB, Old, V, BeginIndex, "vec");
25612565 }
25622566 StoreInst *Store = IRB.CreateAlignedStore(V, &NewAI, NewAI.getAlignment());
25722576 assert(IntTy && "We cannot extract an integer from the alloca");
25732577 assert(!SI.isVolatile());
25742578 if (DL.getTypeSizeInBits(V->getType()) != IntTy->getBitWidth()) {
2575 Value *Old =
2576 IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), "oldload");
2579 Value *Old = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI,
2580 NewAI.getAlignment(), "oldload");
25772581 Old = convertValue(DL, IRB, Old, IntTy);
25782582 assert(BeginOffset >= NewAllocaBeginOffset && "Out of bounds offset");
25792583 uint64_t Offset = BeginOffset - NewAllocaBeginOffset;
27652769 if (NumElements > 1)
27662770 Splat = getVectorSplat(Splat, NumElements);
27672771
2768 Value *Old =
2769 IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), "oldload");
2772 Value *Old = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI,
2773 NewAI.getAlignment(), "oldload");
27702774 V = insertVector(IRB, Old, Splat, BeginIndex, "vec");
27712775 } else if (IntTy) {
27722776 // If this is a memset on an alloca where we can widen stores, insert the
27782782
27792783 if (IntTy && (BeginOffset != NewAllocaBeginOffset ||
27802784 EndOffset != NewAllocaBeginOffset)) {
2781 Value *Old =
2782 IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), "oldload");
2785 Value *Old = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI,
2786 NewAI.getAlignment(), "oldload");
27832787 Old = convertValue(DL, IRB, Old, IntTy);
27842788 uint64_t Offset = NewBeginOffset - NewAllocaBeginOffset;
27852789 V = insertInteger(DL, IRB, Old, V, Offset, "insert");
29392943
29402944 // Reset the other pointer type to match the register type we're going to
29412945 // use, but using the address space of the original other pointer.
2946 Type *OtherTy;
29422947 if (VecTy && !IsWholeAlloca) {
29432948 if (NumElements == 1)
2944 OtherPtrTy = VecTy->getElementType();
2949 OtherTy = VecTy->getElementType();
29452950 else
2946 OtherPtrTy = VectorType::get(VecTy->getElementType(), NumElements);
2947
2948 OtherPtrTy = OtherPtrTy->getPointerTo(OtherAS);
2951 OtherTy = VectorType::get(VecTy->getElementType(), NumElements);
29492952 } else if (IntTy && !IsWholeAlloca) {
2950 OtherPtrTy = SubIntTy->getPointerTo(OtherAS);
2953 OtherTy = SubIntTy;
29512954 } else {
2952 OtherPtrTy = NewAllocaTy->getPointerTo(OtherAS);
2953 }
2955 OtherTy = NewAllocaTy;
2956 }
2957 OtherPtrTy = OtherTy->getPointerTo(OtherAS);
29542958
29552959 Value *SrcPtr = getAdjustedPtr(IRB, DL, OtherPtr, OtherOffset, OtherPtrTy,
29562960 OtherPtr->getName() + ".");
29642968
29652969 Value *Src;
29662970 if (VecTy && !IsWholeAlloca && !IsDest) {
2967 Src = IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), "load");
2971 Src = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI,
2972 NewAI.getAlignment(), "load");
29682973 Src = extractVector(IRB, Src, BeginIndex, EndIndex, "vec");
29692974 } else if (IntTy && !IsWholeAlloca && !IsDest) {
2970 Src = IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), "load");
2975 Src = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI,
2976 NewAI.getAlignment(), "load");
29712977 Src = convertValue(DL, IRB, Src, IntTy);
29722978 uint64_t Offset = NewBeginOffset - NewAllocaBeginOffset;
29732979 Src = extractInteger(DL, IRB, Src, SubIntTy, Offset, "extract");
29742980 } else {
2975 LoadInst *Load = IRB.CreateAlignedLoad(SrcPtr, SrcAlign, II.isVolatile(),
2976 "copyload");
2981 LoadInst *Load = IRB.CreateAlignedLoad(OtherTy, SrcPtr, SrcAlign,
2982 II.isVolatile(), "copyload");
29772983 if (AATags)
29782984 Load->setAAMetadata(AATags);
29792985 Src = Load;
29802986 }
29812987
29822988 if (VecTy && !IsWholeAlloca && IsDest) {
2983 Value *Old =
2984 IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), "oldload");
2989 Value *Old = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI,
2990 NewAI.getAlignment(), "oldload");
29852991 Src = insertVector(IRB, Old, Src, BeginIndex, "vec");
29862992 } else if (IntTy && !IsWholeAlloca && IsDest) {
2987 Value *Old =
2988 IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), "oldload");
2993 Value *Old = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI,
2994 NewAI.getAlignment(), "oldload");
29892995 Old = convertValue(DL, IRB, Old, IntTy);
29902996 uint64_t Offset = NewBeginOffset - NewAllocaBeginOffset;
29912997 Src = insertInteger(DL, IRB, Old, Src, Offset, "insert");
32923298 // Load the single value and insert it using the indices.
32933299 Value *GEP =
32943300 IRB.CreateInBoundsGEP(nullptr, Ptr, GEPIndices, Name + ".gep");
3295 LoadInst *Load = IRB.CreateAlignedLoad(GEP, Align, Name + ".load");
3301 LoadInst *Load = IRB.CreateAlignedLoad(Ty, GEP, Align, Name + ".load");
32963302 if (AATags)
32973303 Load->setAAMetadata(AATags);
32983304 Agg = IRB.CreateInsertValue(Agg, Load, Indices, Name + ".insert");
37863792 auto AS = LI->getPointerAddressSpace();
37873793 auto *PartPtrTy = PartTy->getPointerTo(AS);
37883794 LoadInst *PLoad = IRB.CreateAlignedLoad(
3795 PartTy,
37893796 getAdjustedPtr(IRB, DL, BasePtr,
37903797 APInt(DL.getIndexSizeInBits(AS), PartOffset),
37913798 PartPtrTy, BasePtr->getName() + "."),
39273934 IRB.SetInsertPoint(LI);
39283935 auto AS = LI->getPointerAddressSpace();
39293936 PLoad = IRB.CreateAlignedLoad(
3937 PartTy,
39303938 getAdjustedPtr(IRB, DL, LoadBasePtr,
39313939 APInt(DL.getIndexSizeInBits(AS), PartOffset),
39323940 LoadPartPtrTy, LoadBasePtr->getName() + "."),
742742 Res.resize(NumElems);
743743
744744 for (unsigned I = 0; I < NumElems; ++I)
745 Res[I] = Builder.CreateAlignedLoad(Ptr[I], Layout.getElemAlign(I),
745 Res[I] = Builder.CreateAlignedLoad(Layout.VecTy->getElementType(), Ptr[I],
746 Layout.getElemAlign(I),
746747 LI.getName() + ".i" + Twine(I));
747748 gather(&LI, Res);
748749 return true;
843843 Instruction *TI = newFunction->begin()->getTerminator();
844844 GetElementPtrInst *GEP = GetElementPtrInst::Create(
845845 StructTy, &*AI, Idx, "gep_" + inputs[i]->getName(), TI);
846 RewriteVal = new LoadInst(GEP, "loadgep_" + inputs[i]->getName(), TI);
846 RewriteVal = new LoadInst(StructTy->getElementType(i), GEP,
847 "loadgep_" + inputs[i]->getName(), TI);
847848 } else
848849 RewriteVal = &*AI++;
849850
10531054 } else {
10541055 Output = ReloadOutputs[i];
10551056 }
1056 LoadInst *load = new LoadInst(Output, outputs[i]->getName()+".reload");
1057 LoadInst *load = new LoadInst(outputs[i]->getType(), Output,
1058 outputs[i]->getName() + ".reload");
10571059 Reloads.push_back(load);
10581060 codeReplacer->getInstList().push_back(load);
10591061 std::vector Users(outputs[i]->user_begin(), outputs[i]->user_end());
7171 Value *&V = Loads[PN->getIncomingBlock(i)];
7272 if (!V) {
7373 // Insert the load into the predecessor block
74 V = new LoadInst(Slot, I.getName()+".reload", VolatileLoads,
74 V = new LoadInst(I.getType(), Slot, I.getName() + ".reload",
75 VolatileLoads,
7576 PN->getIncomingBlock(i)->getTerminator());
7677 }
7778 PN->setIncomingValue(i, V);
7980
8081 } else {
8182 // If this is a normal instruction, just insert a load.
82 Value *V = new LoadInst(Slot, I.getName()+".reload", VolatileLoads, U);
83 Value *V = new LoadInst(I.getType(), Slot, I.getName() + ".reload",
84 VolatileLoads, U);
8385 U->replaceUsesOfWith(&I, V);
8486 }
8587 }
140142 for (; isa(InsertPt) || InsertPt->isEHPad(); ++InsertPt)
141143 /* empty */; // Don't insert before PHI nodes or landingpad instrs.
142144
143 Value *V = new LoadInst(Slot, P->getName() + ".reload", &*InsertPt);
145 Value *V =
146 new LoadInst(P->getType(), Slot, P->getName() + ".reload", &*InsertPt);
144147 P->replaceAllUsesWith(V);
145148
146149 // Delete PHI.
7171 // Loop Body
7272 Value *SrcGEP =
7373 LoopBuilder.CreateInBoundsGEP(LoopOpType, SrcAddr, LoopIndex);
74 Value *Load = LoopBuilder.CreateLoad(SrcGEP, SrcIsVolatile);
74 Value *Load = LoopBuilder.CreateLoad(LoopOpType, SrcGEP, SrcIsVolatile);
7575 Value *DstGEP =
7676 LoopBuilder.CreateInBoundsGEP(LoopOpType, DstAddr, LoopIndex);
7777 LoopBuilder.CreateStore(Load, DstGEP, DstIsVolatile);
113113 : RBuilder.CreateBitCast(SrcAddr, SrcPtrType);
114114 Value *SrcGEP = RBuilder.CreateInBoundsGEP(
115115 OpTy, CastedSrc, ConstantInt::get(TypeOfCopyLen, GepIndex));
116 Value *Load = RBuilder.CreateLoad(SrcGEP, SrcIsVolatile);
116 Value *Load = RBuilder.CreateLoad(OpTy, SrcGEP, SrcIsVolatile);
117117
118118 // Cast destination to operand type and store.
119119 PointerType *DstPtrType = PointerType::get(OpTy, DstAS);
180180 LoopIndex->addIncoming(ConstantInt::get(CopyLenType, 0U), PreLoopBB);
181181
182182 Value *SrcGEP = LoopBuilder.CreateInBoundsGEP(LoopOpType, SrcAddr, LoopIndex);
183 Value *Load = LoopBuilder.CreateLoad(SrcGEP, SrcIsVolatile);
183 Value *Load = LoopBuilder.CreateLoad(LoopOpType, SrcGEP, SrcIsVolatile);
184184 Value *DstGEP = LoopBuilder.CreateInBoundsGEP(LoopOpType, DstAddr, LoopIndex);
185185 LoopBuilder.CreateStore(Load, DstGEP, DstIsVolatile);
186186
233233 Value *FullOffset = ResBuilder.CreateAdd(RuntimeBytesCopied, ResidualIndex);
234234 Value *SrcGEP =
235235 ResBuilder.CreateInBoundsGEP(Int8Type, SrcAsInt8, FullOffset);
236 Value *Load = ResBuilder.CreateLoad(SrcGEP, SrcIsVolatile);
236 Value *Load = ResBuilder.CreateLoad(Int8Type, SrcGEP, SrcIsVolatile);
237237 Value *DstGEP =
238238 ResBuilder.CreateInBoundsGEP(Int8Type, DstAsInt8, FullOffset);
239239 ResBuilder.CreateStore(Load, DstGEP, DstIsVolatile);
291291 BasicBlock *OrigBB = InsertBefore->getParent();
292292 Function *F = OrigBB->getParent();
293293
294 Type *EltTy = cast(SrcAddr->getType())->getElementType();
295
294296 // Create the a comparison of src and dst, based on which we jump to either
295297 // the forward-copy part of the function (if src >= dst) or the backwards-copy
296298 // part (if src < dst).
329331 Value *IndexPtr = LoopBuilder.CreateSub(
330332 LoopPhi, ConstantInt::get(TypeOfCopyLen, 1), "index_ptr");
331333 Value *Element = LoopBuilder.CreateLoad(
332 LoopBuilder.CreateInBoundsGEP(SrcAddr, IndexPtr), "element");
334 EltTy, LoopBuilder.CreateInBoundsGEP(SrcAddr, IndexPtr), "element");
333335 LoopBuilder.CreateStore(Element,
334336 LoopBuilder.CreateInBoundsGEP(DstAddr, IndexPtr));
335337 LoopBuilder.CreateCondBr(
346348 IRBuilder<> FwdLoopBuilder(FwdLoopBB);
347349 PHINode *FwdCopyPhi = FwdLoopBuilder.CreatePHI(TypeOfCopyLen, 0, "index_ptr");
348350 Value *FwdElement = FwdLoopBuilder.CreateLoad(
349 FwdLoopBuilder.CreateInBoundsGEP(SrcAddr, FwdCopyPhi), "element");
351 EltTy, FwdLoopBuilder.CreateInBoundsGEP(SrcAddr, FwdCopyPhi), "element");
350352 FwdLoopBuilder.CreateStore(
351353 FwdElement, FwdLoopBuilder.CreateInBoundsGEP(DstAddr, FwdCopyPhi));
352354 Value *FwdIndexPtr = FwdLoopBuilder.CreateAdd(
50895089 Value *GEPIndices[] = {Builder.getInt32(0), Index};
50905090 Value *GEP = Builder.CreateInBoundsGEP(Array->getValueType(), Array,
50915091 GEPIndices, "switch.gep");
5092 return Builder.CreateLoad(GEP, "switch.load");
5092 return Builder.CreateLoad(
5093 cast(Array->getValueType())->getElementType(), GEP,
5094 "switch.load");
50935095 }
50945096 }
50955097 llvm_unreachable("Unknown lookup table kind!");
332332 return ConstantInt::get(CI->getType(), Str1.compare(Str2));
333333
334334 if (HasStr1 && Str1.empty()) // strcmp("", x) -> -*x
335 return B.CreateNeg(
336 B.CreateZExt(B.CreateLoad(Str2P, "strcmpload"), CI->getType()));
335 return B.CreateNeg(B.CreateZExt(
336 B.CreateLoad(B.getInt8Ty(), Str2P, "strcmpload"), CI->getType()));
337337
338338 if (HasStr2 && Str2.empty()) // strcmp(x,"") -> *x
339 return B.CreateZExt(B.CreateLoad(Str1P, "strcmpload"), CI->getType());
339 return B.CreateZExt(B.CreateLoad(B.getInt8Ty(), Str1P, "strcmpload"),
340 CI->getType());
340341
341342 // strcmp(P, "x") -> memcmp(P, "x", 2)
342343 uint64_t Len1 = GetStringLength(Str1P);
396397 }
397398
398399 if (HasStr1 && Str1.empty()) // strncmp("", x, n) -> -*x
399 return B.CreateNeg(
400 B.CreateZExt(B.CreateLoad(Str2P, "strcmpload"), CI->getType()));
400 return B.CreateNeg(B.CreateZExt(
401 B.CreateLoad(B.getInt8Ty(), Str2P, "strcmpload"), CI->getType()));
401402
402403 if (HasStr2 && Str2.empty()) // strncmp(x, "", n) -> *x
403 return B.CreateZExt(B.CreateLoad(Str1P, "strcmpload"), CI->getType());
404 return B.CreateZExt(B.CreateLoad(B.getInt8Ty(), Str1P, "strcmpload"),
405 CI->getType());
404406
405407 uint64_t Len1 = GetStringLength(Str1P);
406408 uint64_t Len2 = GetStringLength(Str2P);
589591 // strlen(x) != 0 --> *x != 0
590592 // strlen(x) == 0 --> *x == 0
591593 if (isOnlyUsedInZeroEqualityComparison(CI))
592 return B.CreateZExt(B.CreateLoad(Src, "strlenfirst"), CI->getType());
594 return B.CreateZExt(B.CreateLoad(B.getIntNTy(CharSize), Src, "strlenfirst"),
595 CI->getType());
593596
594597 return nullptr;
595598 }
843846
844847 // memcmp(S1,S2,1) -> *(unsigned char*)LHS - *(unsigned char*)RHS
845848 if (Len == 1) {
846 Value *LHSV = B.CreateZExt(B.CreateLoad(castToCStr(LHS, B), "lhsc"),
847 CI->getType(), "lhsv");
848 Value *RHSV = B.CreateZExt(B.CreateLoad(castToCStr(RHS, B), "rhsc"),
849 CI->getType(), "rhsv");
849 Value *LHSV =
850 B.CreateZExt(B.CreateLoad(B.getInt8Ty(), castToCStr(LHS, B), "lhsc"),
851 CI->getType(), "lhsv");
852 Value *RHSV =
853 B.CreateZExt(B.CreateLoad(B.getInt8Ty(), castToCStr(RHS, B), "rhsc"),
854 CI->getType(), "rhsv");
850855 return B.CreateSub(LHSV, RHSV, "chardiff");
851856 }
852857
876881 if (!LHSV) {
877882 Type *LHSPtrTy =
878883 IntType->getPointerTo(LHS->getType()->getPointerAddressSpace());
879 LHSV = B.CreateLoad(B.CreateBitCast(LHS, LHSPtrTy), "lhsv");
884 LHSV = B.CreateLoad(IntType, B.CreateBitCast(LHS, LHSPtrTy), "lhsv");
880885 }
881886 if (!RHSV) {
882887 Type *RHSPtrTy =
883888 IntType->getPointerTo(RHS->getType()->getPointerAddressSpace());
884 RHSV = B.CreateLoad(B.CreateBitCast(RHS, RHSPtrTy), "rhsv");
889 RHSV = B.CreateLoad(IntType, B.CreateBitCast(RHS, RHSPtrTy), "rhsv");
885890 }
886891 return B.CreateZExt(B.CreateICmpNE(LHSV, RHSV), CI->getType(), "memcmp");
887892 }
22852290 // If this is writing one byte, turn it into fputc.
22862291 // This optimisation is only valid, if the return value is unused.
22872292 if (Bytes == 1 && CI->use_empty()) { // fwrite(S,1,1,F) -> fputc(S[0],F)
2288 Value *Char = B.CreateLoad(castToCStr(CI->getArgOperand(0), B), "char");
2293 Value *Char = B.CreateLoad(B.getInt8Ty(),
2294 castToCStr(CI->getArgOperand(0), B), "char");
22892295 Value *NewCI = emitFPutC(Char, CI->getArgOperand(3), B, TLI);
22902296 return NewCI ? ConstantInt::get(CI->getType(), 1) : nullptr;
22912297 }
385385 // memdep queries will find the new load. We can't easily remove the old
386386 // load completely because it is already in the value numbering table.
387387 IRBuilder<> Builder(SrcVal->getParent(), ++BasicBlock::iterator(SrcVal));
388 Type *DestPTy = IntegerType::get(LoadTy->getContext(), NewLoadSize * 8);
389 DestPTy =
390 PointerType::get(DestPTy, PtrVal->getType()->getPointerAddressSpace());
388 Type *DestTy = IntegerType::get(LoadTy->getContext(), NewLoadSize * 8);
389 Type *DestPTy =
390 PointerType::get(DestTy, PtrVal->getType()->getPointerAddressSpace());
391391 Builder.SetCurrentDebugLocation(SrcVal->getDebugLoc());
392392 PtrVal = Builder.CreateBitCast(PtrVal, DestPTy);
393 LoadInst *NewLoad = Builder.CreateLoad(PtrVal);
393 LoadInst *NewLoad = Builder.CreateLoad(DestTy, PtrVal);
394394 NewLoad->takeName(SrcVal);
395395 NewLoad->setAlignment(SrcVal->getAlignment());
396396
11801180
11811181 Value *Bitcast =
11821182 Builder.CreateBitCast(L0->getPointerOperand(), VecTy->getPointerTo(AS));
1183 LoadInst *LI = Builder.CreateAlignedLoad(Bitcast, Alignment);
1183 LoadInst *LI = Builder.CreateAlignedLoad(VecTy, Bitcast, Alignment);
11841184 propagateMetadata(LI, Chain);
11851185
11861186 if (VecLoadTy) {
20992099 GroupMask, UndefVec, "wide.masked.vec");
21002100 }
21012101 else
2102 NewLoad = Builder.CreateAlignedLoad(NewPtrs[Part],
2103 Group->getAlignment(), "wide.vec");
2102 NewLoad = Builder.CreateAlignedLoad(VecTy, NewPtrs[Part],
2103 Group->getAlignment(), "wide.vec");
21042104 Group->addMetadata(NewLoad);
21052105 NewLoads.push_back(NewLoad);
21062106 }
23112311 UndefValue::get(DataTy),
23122312 "wide.masked.load");
23132313 else
2314 NewLI = Builder.CreateAlignedLoad(VecPtr, Alignment, "wide.load");
2314 NewLI =
2315 Builder.CreateAlignedLoad(DataTy, VecPtr, Alignment, "wide.load");
23152316
23162317 // Add metadata to the load, but setVectorValue to the reverse shuffle.
23172318 addMetadata(NewLI, LI);
31353135 Builder.SetInsertPoint(LI);
31363136 PointerType *PtrTy = PointerType::get(VecTy, LI->getPointerAddressSpace());
31373137 Value *Ptr = Builder.CreateBitCast(LI->getOperand(0), PtrTy);
3138 LoadInst *V = Builder.CreateAlignedLoad(Ptr, LI->getAlignment());
3138 LoadInst *V = Builder.CreateAlignedLoad(VecTy, Ptr, LI->getAlignment());
31393139 Value *NewV = propagateMetadata(V, E->Scalars);
31403140 if (!E->ReorderIndices.empty()) {
31413141 OrdersType Mask;
33403340 ExternalUses.push_back(ExternalUser(PO, cast(VecPtr), 0));
33413341
33423342 unsigned Alignment = LI->getAlignment();
3343 LI = Builder.CreateLoad(VecPtr);
3343 LI = Builder.CreateLoad(VecTy, VecPtr);
33443344 if (!Alignment) {
33453345 Alignment = DL->getABITypeAlignment(ScalarLoadTy);
33463346 }
305305 ; HSA-LABEL: @kern_v3i32(
306306 ; HSA-NEXT: [[KERN_V3I32_KERNARG_SEGMENT:%.*]] = call nonnull align 16 dereferenceable(16) i8 addrspace(4)* @llvm.amdgcn.kernarg.segment.ptr()
307307 ; HSA-NEXT: [[ARG0_KERNARG_OFFSET:%.*]] = getelementptr inbounds i8, i8 addrspace(4)* [[KERN_V3I32_KERNARG_SEGMENT]], i64 0
308 ; HSA-NEXT: [[ARG0_KERNARG_OFFSET_CAST:%.*]] = bitcast i8 addrspace(4)* [[ARG0_KERNARG_OFFSET]] to <3 x i32> addrspace(4)*
309 ; HSA-NEXT: [[TMP1:%.*]] = bitcast <3 x i32> addrspace(4)* [[ARG0_KERNARG_OFFSET_CAST]] to <4 x i32> addrspace(4)*
310 ; HSA-NEXT: [[TMP2:%.*]] = load <4 x i32>, <4 x i32> addrspace(4)* [[TMP1]], align 16, !invariant.load !0
311 ; HSA-NEXT: [[ARG0_LOAD:%.*]] = shufflevector <4 x i32> [[TMP2]], <4 x i32> undef, <3 x i32>
308 ; HSA-NEXT: [[ARG0_KERNARG_OFFSET_CAST:%.*]] = bitcast i8 addrspace(4)* [[ARG0_KERNARG_OFFSET]] to <4 x i32> addrspace(4)*
309 ; HSA-NEXT: [[TMP:%.*]] = load <4 x i32>, <4 x i32> addrspace(4)* [[ARG0_KERNARG_OFFSET_CAST]], align 16, !invariant.load !0
310 ; HSA-NEXT: [[ARG0_LOAD:%.*]] = shufflevector <4 x i32> [[TMP]], <4 x i32> undef, <3 x i32>
312311 ; HSA-NEXT: store <3 x i32> [[ARG0_LOAD]], <3 x i32> addrspace(1)* undef, align 4
313312 ; HSA-NEXT: ret void
314313 ;
315314 ; MESA-LABEL: @kern_v3i32(
316315 ; MESA-NEXT: [[KERN_V3I32_KERNARG_SEGMENT:%.*]] = call nonnull align 16 dereferenceable(52) i8 addrspace(4)* @llvm.amdgcn.kernarg.segment.ptr()
317316 ; MESA-NEXT: [[ARG0_KERNARG_OFFSET:%.*]] = getelementptr inbounds i8, i8 addrspace(4)* [[KERN_V3I32_KERNARG_SEGMENT]], i64 36
318 ; MESA-NEXT: [[ARG0_KERNARG_OFFSET_CAST:%.*]] = bitcast i8 addrspace(4)* [[ARG0_KERNARG_OFFSET]] to <3 x i32> addrspace(4)*
319 ; MESA-NEXT: [[TMP1:%.*]] = bitcast <3 x i32> addrspace(4)* [[ARG0_KERNARG_OFFSET_CAST]] to <4 x i32> addrspace(4)*
320 ; MESA-NEXT: [[TMP2:%.*]] = load <4 x i32>, <4 x i32> addrspace(4)* [[TMP1]], align 4, !invariant.load !0
321 ; MESA-NEXT: [[ARG0_LOAD:%.*]] = shufflevector <4 x i32> [[TMP2]], <4 x i32> undef, <3 x i32>
317 ; MESA-NEXT: [[ARG0_KERNARG_OFFSET_CAST:%.*]] = bitcast i8 addrspace(4)* [[ARG0_KERNARG_OFFSET]] to <4 x i32> addrspace(4)*
318 ; MESA-NEXT: [[TMP:%.*]] = load <4 x i32>, <4 x i32> addrspace(4)* [[ARG0_KERNARG_OFFSET_CAST]], align 4, !invariant.load !0
319 ; MESA-NEXT: [[ARG0_LOAD:%.*]] = shufflevector <4 x i32> [[TMP]], <4 x i32> undef, <3 x i32>
322320 ; MESA-NEXT: store <3 x i32> [[ARG0_LOAD]], <3 x i32> addrspace(1)* undef, align 4
323321 ; MESA-NEXT: ret void
324322 ;
396394 ; HSA-NEXT: [[ARG0_KERNARG_OFFSET_CAST:%.*]] = bitcast i8 addrspace(4)* [[ARG0_KERNARG_OFFSET]] to i32 addrspace(4)*
397395 ; HSA-NEXT: [[ARG0_LOAD:%.*]] = load i32, i32 addrspace(4)* [[ARG0_KERNARG_OFFSET_CAST]], align 16, !invariant.load !0
398396 ; HSA-NEXT: [[ARG1_KERNARG_OFFSET:%.*]] = getelementptr inbounds i8, i8 addrspace(4)* [[KERN_I32_V3I32_KERNARG_SEGMENT]], i64 16
399 ; HSA-NEXT: [[ARG1_KERNARG_OFFSET_CAST:%.*]] = bitcast i8 addrspace(4)* [[ARG1_KERNARG_OFFSET]] to <3 x i32> addrspace(4)*
400 ; HSA-NEXT: [[TMP1:%.*]] = bitcast <3 x i32> addrspace(4)* [[ARG1_KERNARG_OFFSET_CAST]] to <4 x i32> addrspace(4)*
401 ; HSA-NEXT: [[TMP2:%.*]] = load <4 x i32>, <4 x i32> addrspace(4)* [[TMP1]], align 16, !invariant.load !0
402 ; HSA-NEXT: [[ARG1_LOAD:%.*]] = shufflevector <4 x i32> [[TMP2]], <4 x i32> undef, <3 x i32>
397 ; HSA-NEXT: [[ARG1_KERNARG_OFFSET_CAST:%.*]] = bitcast i8 addrspace(4)* [[ARG1_KERNARG_OFFSET]] to <4 x i32> addrspace(4)*
398 ; HSA-NEXT: [[TMP:%.*]] = load <4 x i32>, <4 x i32> addrspace(4)* [[ARG1_KERNARG_OFFSET_CAST]], align 16, !invariant.load !0
399 ; HSA-NEXT: [[ARG1_LOAD:%.*]] = shufflevector <4 x i32> [[TMP]], <4 x i32> undef, <3 x i32>
403400 ; HSA-NEXT: store i32 [[ARG0_LOAD]], i32 addrspace(1)* undef
404401 ; HSA-NEXT: store <3 x i32> [[ARG1_LOAD]], <3 x i32> addrspace(1)* undef, align 4
405402 ; HSA-NEXT: ret void
410407 ; MESA-NEXT: [[ARG0_KERNARG_OFFSET_CAST:%.*]] = bitcast i8 addrspace(4)* [[ARG0_KERNARG_OFFSET]] to i32 addrspace(4)*
411408 ; MESA-NEXT: [[ARG0_LOAD:%.*]] = load i32, i32 addrspace(4)* [[ARG0_KERNARG_OFFSET_CAST]], align 4, !invariant.load !0
412409 ; MESA-NEXT: [[ARG1_KERNARG_OFFSET:%.*]] = getelementptr inbounds i8, i8 addrspace(4)* [[KERN_I32_V3I32_KERNARG_SEGMENT]], i64 52
413 ; MESA-NEXT: [[ARG1_KERNARG_OFFSET_CAST:%.*]] = bitcast i8 addrspace(4)* [[ARG1_KERNARG_OFFSET]] to <3 x i32> addrspace(4)*
414 ; MESA-NEXT: [[TMP1:%.*]] = bitcast <3 x i32> addrspace(4)* [[ARG1_KERNARG_OFFSET_CAST]] to <4 x i32> addrspace(4)*
415 ; MESA-NEXT: [[TMP2:%.*]] = load <4 x i32>, <4 x i32> addrspace(4)* [[TMP1]], align 4, !invariant.load !0
416 ; MESA-NEXT: [[ARG1_LOAD:%.*]] = shufflevector <4 x i32> [[TMP2]], <4 x i32> undef, <3 x i32>
410 ; MESA-NEXT: [[ARG1_KERNARG_OFFSET_CAST:%.*]] = bitcast i8 addrspace(4)* [[ARG1_KERNARG_OFFSET]] to <4 x i32> addrspace(4)*
411 ; MESA-NEXT: [[TMP:%.*]] = load <4 x i32>, <4 x i32> addrspace(4)* [[ARG1_KERNARG_OFFSET_CAST]], align 4, !invariant.load !0
412 ; MESA-NEXT: [[ARG1_LOAD:%.*]] = shufflevector <4 x i32> [[TMP]], <4 x i32> undef, <3 x i32>
417413 ; MESA-NEXT: store i32 [[ARG0_LOAD]], i32 addrspace(1)* undef
418414 ; MESA-NEXT: store <3 x i32> [[ARG1_LOAD]], <3 x i32> addrspace(1)* undef, align 4
419415 ; MESA-NEXT: ret void
878878 BasicBlock::Create(F->getContext(), "lookupfp", FuncWrapper);
879879
880880 // Check to see if we already looked up the value.
881 Value *CachedVal = new LoadInst(Cache, "fpcache", EntryBB);
881 Value *CachedVal =
882 new LoadInst(F->getType(), Cache, "fpcache", EntryBB);
882883 Value *IsNull = new ICmpInst(*EntryBB, ICmpInst::ICMP_EQ, CachedVal,
883884 NullPtr, "isNull");
884885 BranchInst::Create(LookupBB, DoCallBB, IsNull, EntryBB);
173173 auto *Addr = ConstantPointerNull::get(PtrType);
174174
175175 auto *Store1 = new StoreInst(Value, Addr, BB);
176 auto *Load1 = new LoadInst(Addr, "load", BB);
176 auto *Load1 = new LoadInst(IntType, Addr, "load", BB);
177177 auto *Add1 = BinaryOperator::CreateAdd(Value, Value, "add", BB);
178178 auto *VAArg1 = new VAArgInst(Addr, PtrType, "vaarg", BB);
179179 auto *CmpXChg1 = new AtomicCmpXchgInst(
9191 MemorySSAUpdater Updater(&MSSA);
9292 // Add the load
9393 B.SetInsertPoint(Merge);
94 LoadInst *LoadInst = B.CreateLoad(PointerArg);
94 LoadInst *LoadInst = B.CreateLoad(B.getInt8Ty(), PointerArg);
9595
9696 // MemoryPHI should already exist.
9797 MemoryPhi *MP = MSSA.getMemoryAccess(Merge);
137137
138138 // Add the load
139139 B.SetInsertPoint(Merge, Merge->begin());
140 LoadInst *FirstLoad = B.CreateLoad(PointerArg);
140 LoadInst *FirstLoad = B.CreateLoad(B.getInt8Ty(), PointerArg);
141141
142142 // MemoryPHI should not already exist.
143143 MemoryPhi *MP = MSSA.getMemoryAccess(Merge);
161161 // We don't touch existing loads, so we need to create a new one to get a phi
162162 // Add the second load
163163 B.SetInsertPoint(Merge, Merge->begin());
164 LoadInst *SecondLoad = B.CreateLoad(PointerArg);
164 LoadInst *SecondLoad = B.CreateLoad(B.getInt8Ty(), PointerArg);
165165
166166 // MemoryPHI should not already exist.
167167 MP = MSSA.getMemoryAccess(Merge);
227227
228228 // Add the load
229229 B.SetInsertPoint(Merge, Merge->begin());
230 LoadInst *LoadInst = B.CreateLoad(PointerArg);
230 LoadInst *LoadInst = B.CreateLoad(B.getInt8Ty(), PointerArg);
231231
232232 // MemoryPHI should not already exist.
233233 MemoryPhi *MP = MSSA.getMemoryAccess(Merge);
261261
262262 // Load in left block
263263 B.SetInsertPoint(Left, Left->begin());
264 LoadInst *LoadInst1 = B.CreateLoad(PointerArg);
264 LoadInst *LoadInst1 = B.CreateLoad(B.getInt8Ty(), PointerArg);
265265 // Store in merge block
266266 B.SetInsertPoint(Merge, Merge->begin());
267267 B.CreateStore(B.getInt8(16), PointerArg);
309309 BranchInst::Create(Merge, Left);
310310 BranchInst::Create(Merge, Right);
311311 B.SetInsertPoint(Merge);
312 B.CreateLoad(PointerArg);
312 B.CreateLoad(B.getInt8Ty(), PointerArg);
313313 setupAnalyses();
314314 MemorySSA &MSSA = *Analyses->MSSA;
315315 MemorySSAUpdater Updater(&MSSA);
345345 BranchInst::Create(Merge, Left);
346346 BranchInst::Create(Merge, Right);
347347 B.SetInsertPoint(Merge);
348 auto *MergeLoad = B.CreateLoad(PointerArg);
348 auto *MergeLoad = B.CreateLoad(B.getInt8Ty(), PointerArg);
349349 setupAnalyses();
350350 MemorySSA &MSSA = *Analyses->MSSA;
351351 MemorySSAUpdater Updater(&MSSA);
391391 BranchInst::Create(Merge, Left);
392392 BranchInst::Create(Merge, Right);
393393 B.SetInsertPoint(Merge);
394 auto *MergeLoad = B.CreateLoad(PointerArg);
394 auto *MergeLoad = B.CreateLoad(B.getInt8Ty(), PointerArg);
395395 setupAnalyses();
396396 MemorySSA &MSSA = *Analyses->MSSA;
397397 MemorySSAUpdater Updater(&MSSA);
435435 BranchInst::Create(Merge, Left);
436436 BranchInst::Create(Merge, Right);
437437 B.SetInsertPoint(Merge);
438 auto *MergeLoad = B.CreateLoad(PointerArg);
438 auto *MergeLoad = B.CreateLoad(B.getInt8Ty(), PointerArg);
439439 setupAnalyses();
440440 MemorySSA &MSSA = *Analyses->MSSA;
441441 MemorySSAUpdater Updater(&MSSA);
489489 BranchInst::Create(Merge, Left);
490490 BranchInst::Create(Merge, Right);
491491 B.SetInsertPoint(Merge);
492 LoadInst *LoadInst = B.CreateLoad(PointerArg);
492 LoadInst *LoadInst = B.CreateLoad(B.getInt8Ty(), PointerArg);
493493
494494 setupAnalyses();
495495 MemorySSA &MSSA = *Analyses->MSSA;
534534 BranchInst::Create(Merge, Left);
535535 BranchInst::Create(Merge, Right);
536536 B.SetInsertPoint(Merge);
537 LoadInst *LoadInst = B.CreateLoad(PointerArg);
537 LoadInst *LoadInst = B.CreateLoad(B.getInt8Ty(), PointerArg);
538538
539539 setupAnalyses();
540540 MemorySSA &MSSA = *Analyses->MSSA;
630630 Type *Int8 = Type::getInt8Ty(C);
631631 Value *Alloca = B.CreateAlloca(Int8, ConstantInt::get(Int8, 1), "A");
632632 Instruction *SI = B.CreateStore(ConstantInt::get(Int8, 0), Alloca);
633 Instruction *LI = B.CreateLoad(Alloca);
633 Instruction *LI = B.CreateLoad(Int8, Alloca);
634634
635635 setupAnalyses();
636636 MemorySSA &MSSA = *Analyses->MSSA;
714714 B.SetInsertPoint(IfThen);
715715 Instruction *FirstStore = B.CreateStore(Zero, AllocA);
716716 B.CreateStore(Zero, AllocB);
717 Instruction *ALoad0 = B.CreateLoad(AllocA, "");
717 Instruction *ALoad0 = B.CreateLoad(Int8, AllocA, "");
718718 Instruction *BStore = B.CreateStore(Zero, AllocB);
719719 // Due to use optimization/etc. we make a store to A, which is removed after
720720 // we build MSSA. This helps keep the test case simple-ish.
721721 Instruction *KillStore = B.CreateStore(Zero, AllocA);
722 Instruction *ALoad = B.CreateLoad(AllocA, "");
722 Instruction *ALoad = B.CreateLoad(Int8, AllocA, "");
723723 B.CreateBr(IfEnd);
724724
725725 B.SetInsertPoint(IfEnd);
770770 Value *AllocA = B.CreateAlloca(Int8, One, "");
771771
772772 Instruction *Store = B.CreateStore(One, AllocA);
773 Instruction *Load = B.CreateLoad(AllocA);
773 Instruction *Load = B.CreateLoad(Int8, AllocA);
774774
775775 setupAnalyses();
776776 MemorySSA &MSSA = *Analyses->MSSA;
799799 Instruction *SIA = B.CreateStore(ConstantInt::get(Int8, 0), AllocaA);
800800 Value *AllocaB = B.CreateAlloca(Int8, ConstantInt::get(Int8, 1), "B");
801801 Instruction *SIB = B.CreateStore(ConstantInt::get(Int8, 0), AllocaB);
802 Instruction *LIA = B.CreateLoad(AllocaA);
802 Instruction *LIA = B.CreateLoad(Int8, AllocaA);
803803
804804 setupAnalyses();
805805 MemorySSA &MSSA = *Analyses->MSSA;
833833
834834 StoreInst *StoreA0 = B.CreateStore(ConstantInt::get(Int8, 0), A);
835835 StoreInst *StoreB = B.CreateStore(ConstantInt::get(Int8, 0), B_);
836 LoadInst *LoadB = B.CreateLoad(B_);
836 LoadInst *LoadB = B.CreateLoad(Int8, B_);
837837 StoreInst *StoreA1 = B.CreateStore(ConstantInt::get(Int8, 4), A);
838838 StoreInst *StoreC = B.CreateStore(ConstantInt::get(Int8, 4), C);
839839 StoreInst *StoreA2 = B.CreateStore(ConstantInt::get(Int8, 4), A);
840 LoadInst *LoadC = B.CreateLoad(C);
840 LoadInst *LoadC = B.CreateLoad(Int8, C);
841841
842842 setupAnalyses();
843843 MemorySSA &MSSA = *Analyses->MSSA;
901901 MemorySSA &MSSA = *Analyses->MSSA;
902902 MemorySSAUpdater Updater(&MSSA);
903903 // Create the load memory acccess
904 LoadInst *LoadInst = B.CreateLoad(FirstArg);
904 LoadInst *LoadInst = B.CreateLoad(B.getInt8Ty(), FirstArg);
905905 MemoryUse *LoadAccess = cast(Updater.createMemoryAccessInBB(
906906 LoadInst, nullptr, AfterLoopBB, MemorySSA::Beginning));
907907 Updater.insertUse(LoadAccess);
10091009
10101010 B.CreateStore(ConstantInt::get(Int8, 1), AllocaB);
10111011 // Check load from LOE
1012 LoadInst *LA1 = B.CreateLoad(AllocaA, "");
1012 LoadInst *LA1 = B.CreateLoad(Int8, AllocaA, "");
10131013 // Check load alias cached for second load
1014 LoadInst *LA2 = B.CreateLoad(AllocaA, "");
1014 LoadInst *LA2 = B.CreateLoad(Int8, AllocaA, "");
10151015
10161016 B.CreateStore(ConstantInt::get(Int8, 1), AllocaA);
10171017 // Check load from store/def
1018 LoadInst *LA3 = B.CreateLoad(AllocaA, "");
1018 LoadInst *LA3 = B.CreateLoad(Int8, AllocaA, "");
10191019 // Check load alias cached for second load
1020 LoadInst *LA4 = B.CreateLoad(AllocaA, "");
1020 LoadInst *LA4 = B.CreateLoad(Int8, AllocaA, "");
10211021
10221022 setupAnalyses();
10231023 MemorySSA &MSSA = *Analyses->MSSA;
11021102 Argument *PointerA = &*ArgIt;
11031103 Argument *PointerB = &*(++ArgIt);
11041104 B.CreateStore(ConstantInt::get(Int8, 1), PointerB);
1105 LoadInst *LA1 = B.CreateLoad(PointerA, "");
1105 LoadInst *LA1 = B.CreateLoad(Int8, PointerA, "");
11061106 B.CreateStore(ConstantInt::get(Int8, 0), PointerA);
1107 LoadInst *LB1 = B.CreateLoad(PointerB, "");
1107 LoadInst *LB1 = B.CreateLoad(Int8, PointerB, "");
11081108 B.CreateStore(ConstantInt::get(Int8, 0), PointerA);
1109 LoadInst *LA2 = B.CreateLoad(PointerA, "");
1109 LoadInst *LA2 = B.CreateLoad(Int8, PointerA, "");
11101110 B.CreateStore(ConstantInt::get(Int8, 0), PointerB);
1111 LoadInst *LB2 = B.CreateLoad(PointerB, "");
1111 LoadInst *LB2 = B.CreateLoad(Int8, PointerB, "");
11121112
11131113 setupAnalyses();
11141114 MemorySSA &MSSA = *Analyses->MSSA;
4343 BasicBlock *BBX = BasicBlock::Create(Ctx, "bbx", F);
4444 B.SetInsertPoint(BBX);
4545 Argument *PointerArg = &*F->arg_begin();
46 LoadInst *LoadInstX = B.CreateLoad(PointerArg);
47 LoadInst *LoadInstY = B.CreateLoad(PointerArg);
46 LoadInst *LoadInstX = B.CreateLoad(B.getInt8Ty(), PointerArg);
47 LoadInst *LoadInstY = B.CreateLoad(B.getInt8Ty(), PointerArg);
4848
4949 // Create BBY with 1 load.
5050 BasicBlock *BBY = BasicBlock::Create(Ctx, "bby", F);
5151 B.SetInsertPoint(BBY);
52 LoadInst *LoadInstZ = B.CreateLoad(PointerArg);
52 LoadInst *LoadInstZ = B.CreateLoad(B.getInt8Ty(), PointerArg);
5353 B.CreateRet(LoadInstZ);
5454 std::unique_ptr DT(new DominatorTree(*F));
5555 OrderedInstructions OI(&*DT);
3636 BranchInst::Create(Then, If);
3737 BranchInst::Create(Then, Else);
3838
39 Value *Val1 = new LoadInst(UndefValue::get(I32PtrTy), "val1", Entry);
40 Value *Val2 = new LoadInst(UndefValue::get(I32PtrTy), "val2", Entry);
41 Value *Val3 = new LoadInst(UndefValue::get(I32PtrTy), "val3", Entry);
42 Value *Val4 = new LoadInst(UndefValue::get(I32PtrTy), "val4", Entry);
39 Value *Val1 = new LoadInst(I32Ty, UndefValue::get(I32PtrTy), "val1", Entry);
40 Value *Val2 = new LoadInst(I32Ty, UndefValue::get(I32PtrTy), "val2", Entry);
41 Value *Val3 = new LoadInst(I32Ty, UndefValue::get(I32PtrTy), "val3", Entry);
42 Value *Val4 = new LoadInst(I32Ty, UndefValue::get(I32PtrTy), "val4", Entry);
4343
4444 PHINode *Phi1 = PHINode::Create(I32Ty, 2, "phi1", Then);
4545 Phi1->addIncoming(Val1, If);
109109 BranchInst::Create(End, If2);
110110 BranchInst::Create(End, Else2);
111111
112 Value *Val1 = new LoadInst(UndefValue::get(I32PtrTy), "val1", Entry);
113 Value *Val2 = new LoadInst(UndefValue::get(I32PtrTy), "val2", Entry);
114 Value *Val3 = new LoadInst(UndefValue::get(I32PtrTy), "val3", Entry);
115 Value *Val4 = new LoadInst(UndefValue::get(I32PtrTy), "val4", Entry);
112 Value *Val1 = new LoadInst(I32Ty, UndefValue::get(I32PtrTy), "val1", Entry);
113 Value *Val2 = new LoadInst(I32Ty, UndefValue::get(I32PtrTy), "val2", Entry);
114 Value *Val3 = new LoadInst(I32Ty, UndefValue::get(I32PtrTy), "val3", Entry);
115 Value *Val4 = new LoadInst(I32Ty, UndefValue::get(I32PtrTy), "val4", Entry);
116116
117117 PHINode *Phi1 = PHINode::Create(I32Ty, 2, "phi1", Then);
118118 Phi1->addIncoming(Val1, If1);
406406
407407 const int ValueDepth = 10;
408408 for (int i = 0; i < ValueDepth; i++) {
409 X = new LoadInst(new IntToPtrInst(X, IntPtrPtrTy, "", EntryBB), "",
409 X = new LoadInst(IntPtrTy, new IntToPtrInst(X, IntPtrPtrTy, "", EntryBB),
410 "",
410411 /*isVolatile*/ false, EntryBB);
411 Y = new LoadInst(new IntToPtrInst(Y, IntPtrPtrTy, "", EntryBB), "",
412 Y = new LoadInst(IntPtrTy, new IntToPtrInst(Y, IntPtrPtrTy, "", EntryBB),
413 "",
412414 /*isVolatile*/ false, EntryBB);
413415 }
414416
380380 BasicBlock *Else = BasicBlock::Create(Context, "else", F);
381381 F->arg_begin()->setName("cond");
382382 Builder.SetInsertPoint(If);
383 LoadInst *Cond = Builder.CreateLoad(F->arg_begin());
383 LoadInst *Cond = Builder.CreateLoad(Type::getInt1Ty(Context), F->arg_begin());
384384 Builder.CreateCondBr(Cond, Then, Else);
385385 Builder.SetInsertPoint(Then);
386386 Builder.CreateRet(Builder.getInt64(1));
420420 BasicBlock *Else = BasicBlock::Create(Context, "else", F);
421421 F->arg_begin()->setName("cond");
422422 Builder.SetInsertPoint(If);
423 LoadInst *Cond = Builder.CreateLoad(F->arg_begin());
423 LoadInst *Cond = Builder.CreateLoad(Type::getInt1Ty(Context), F->arg_begin());
424424 Builder.CreateCondBr(Cond, Then, Else);
425425 Builder.SetInsertPoint(Then);
426426 Builder.CreateRet(Builder.getInt64(0));
210210 GVB = insertGlobalInt32(B.get(), "GVB", initialNum);
211211 FA = startFunction(A.get(),
212212 FunctionType::get(Builder.getInt32Ty(), {}, false), "FA");
213 endFunctionWithRet(FA, Builder.CreateLoad(GVA));
213 endFunctionWithRet(FA, Builder.CreateLoad(Builder.getInt32Ty(), GVA));
214214 FB = startFunction(B.get(),
215215 FunctionType::get(Builder.getInt32Ty(), {}, false), "FB");
216 endFunctionWithRet(FB, Builder.CreateLoad(GVB));
216 endFunctionWithRet(FB, Builder.CreateLoad(Builder.getInt32Ty(), GVB));
217217
218218 GVC = insertGlobalInt32(B.get(), "GVC", initialNum);
219219 GVC->setLinkage(GlobalValue::InternalLinkage);
100100 Function *ReturnGlobal =
101101 startFunction(M.get(), FunctionType::get(Builder.getInt32Ty(), {}, false),
102102 "ReturnGlobal");
103 Value *ReadGlobal = Builder.CreateLoad(GV);
103 Value *ReadGlobal = Builder.CreateLoad(Builder.getInt32Ty(), GV);
104104 endFunctionWithRet(ReturnGlobal, ReadGlobal);
105105
106106 createJIT(std::move(M));
5353 CallInst *Call;
5454 IntrinsicInst *II;
5555
56 V = Builder.CreateLoad(GV);
56 V = Builder.CreateLoad(GV->getValueType(), GV);
5757 I = cast(Builder.CreateFAdd(V, V));
5858 I->setHasNoInfs(true);
5959 I->setHasNoNaNs(false);
206206 Value *F, *FC;
207207 Instruction *FDiv, *FAdd, *FCmp, *FCall;
208208
209 F = Builder.CreateLoad(GV);
209 F = Builder.CreateLoad(GV->getValueType(), GV);
210210 F = Builder.CreateFAdd(F, F);
211211
212212 EXPECT_FALSE(Builder.getFastMathFlags().any());
393393 // Test instructions.
394394 GlobalVariable *G = new GlobalVariable(*M, Builder.getInt32Ty(), true,
395395 GlobalValue::ExternalLinkage, nullptr);
396 Value *V = Builder.CreateLoad(G);
396 Value *V = Builder.CreateLoad(G->getValueType(), G);
397397 EXPECT_TRUE(
398398 cast(Builder.CreateNSWAdd(V, V))->hasNoSignedWrap());
399399 EXPECT_TRUE(
460460 EXPECT_FALSE(Builder.getFastMathFlags().allowReciprocal());
461461 EXPECT_EQ(FPMathA, Builder.getDefaultFPMathTag());
462462
463 Value *F = Builder.CreateLoad(GV);
463 Value *F = Builder.CreateLoad(GV->getValueType(), GV);
464464
465465 {
466466 IRBuilder<>::InsertPointGuard Guard(Builder);
396396 // store i32 42, i32* %0
397397
398398 Value *Alloca = IRB.CreateAlloca(IRB.getInt32Ty());
399 Value *LoadInst = IRB.CreateLoad(Alloca);
399 Value *LoadInst = IRB.CreateLoad(IRB.getInt32Ty(), Alloca);
400400 Value *FourtyTwo = IRB.getInt32(42);
401401 Value *StoreInst = IRB.CreateStore(FourtyTwo, Alloca);
402402 Value *MatchLoad, *MatchStoreVal, *MatchStorePointer;
8282 GEPIndices.push_back(&*F->arg_begin());
8383
8484 Value *GEP = Builder.CreateGEP(AT, GV, GEPIndices, "switch.gep");
85 Value *Load = Builder.CreateLoad(GEP, "switch.load");
85 Value *Load = Builder.CreateLoad(AT->getElementType(), GEP, "switch.load");
8686
8787 Builder.CreateRet(Load);
8888
907907 ASSERT_THAT(BBI, F.end());
908908 auto CreateCondBr = [&](BasicBlock *TrueBB, BasicBlock *FalseBB,
909909 const char *Name, BasicBlock *BB) {
910 auto *Cond = new LoadInst(&Ptr, Name, /*isVolatile*/ true, BB);
910 auto *Cond = new LoadInst(Type::getInt1Ty(Context), &Ptr, Name,
911 /*isVolatile*/ true, BB);
911912 BranchInst::Create(TrueBB, FalseBB, Cond, BB);
912913 };
913914
11091110 ASSERT_THAT(BBI, F.end());
11101111 auto CreateCondBr = [&](BasicBlock *TrueBB, BasicBlock *FalseBB,
11111112 const char *Name, BasicBlock *BB) {
1112 auto *Cond = new LoadInst(&Ptr, Name, /*isVolatile*/ true, BB);
1113 auto *Cond = new LoadInst(Type::getInt1Ty(Context), &Ptr, Name,
1114 /*isVolatile*/ true, BB);
11131115 BranchInst::Create(TrueBB, FalseBB, Cond, BB);
11141116 };
11151117
15021504 auto *NewLoop03BB =
15031505 BasicBlock::Create(Context, "loop.0.3", &F, &Loop0LatchBB);
15041506 BranchInst::Create(NewLoop03BB, NewLoop03PHBB);
1505 auto *Cond = new LoadInst(&Ptr, "cond.0.3", /*isVolatile*/ true,
1506 NewLoop03BB);
1507 auto *Cond =
1508 new LoadInst(Type::getInt1Ty(Context), &Ptr, "cond.0.3",
1509 /*isVolatile*/ true, NewLoop03BB);
15071510 BranchInst::Create(&Loop0LatchBB, NewLoop03BB, Cond, NewLoop03BB);
15081511 Loop02PHBB.getTerminator()->replaceUsesOfWith(&Loop0LatchBB,
15091512 NewLoop03PHBB);
3030 BB = BasicBlock::Create(Ctx, "", F);
3131 B.SetInsertPoint(BB);
3232 Argument *PointerArg = &*F->arg_begin();
33 LoadInst *LoadInst = B.CreateLoad(PointerArg);
33 LoadInst *LoadInst = B.CreateLoad(T, PointerArg);
3434 C = B.getInt8(addVal);
3535 I = cast(B.CreateAdd(LoadInst, C));
3636 B.CreateRet(I);