Skip to content

Commit cfa582e

Browse files
authored
SimplifyLibCalls: Use default globals address space when building new global strings. (#118729)
Writing a test for this transitively exposed a number of places in BuildLibCalls where we were failing to propagate address spaces properly, which are additionally fixed.
1 parent 6f21401 commit cfa582e

File tree

5 files changed

+170
-111
lines changed

5 files changed

+170
-111
lines changed

llvm/include/llvm/Transforms/Utils/BuildLibCalls.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -246,32 +246,32 @@ namespace llvm {
246246
const DataLayout &DL, const TargetLibraryInfo *TLI);
247247

248248
/// Emit a call to the malloc function.
249-
Value *emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL,
250-
const TargetLibraryInfo *TLI);
249+
Value *emitMalloc(Type *RetTy, Value *Num, IRBuilderBase &B,
250+
const DataLayout &DL, const TargetLibraryInfo *TLI);
251251

252252
/// Emit a call to the calloc function.
253-
Value *emitCalloc(Value *Num, Value *Size, IRBuilderBase &B,
254-
const TargetLibraryInfo &TLI, unsigned AddrSpace);
253+
Value *emitCalloc(Type *RetTy, Value *Num, Value *Size, IRBuilderBase &B,
254+
const TargetLibraryInfo &TLI);
255255

256256
/// Emit a call to the hot/cold operator new function.
257-
Value *emitHotColdNew(Value *Num, IRBuilderBase &B,
257+
Value *emitHotColdNew(Type *RetTy, Value *Num, IRBuilderBase &B,
258258
const TargetLibraryInfo *TLI, LibFunc NewFunc,
259259
uint8_t HotCold);
260-
Value *emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B,
261-
const TargetLibraryInfo *TLI, LibFunc NewFunc,
262-
uint8_t HotCold);
263-
Value *emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B,
264-
const TargetLibraryInfo *TLI, LibFunc NewFunc,
265-
uint8_t HotCold);
266-
Value *emitHotColdNewAlignedNoThrow(Value *Num, Value *Align, Value *NoThrow,
267-
IRBuilderBase &B,
260+
Value *emitHotColdNewNoThrow(Type *RetTy, Value *Num, Value *NoThrow,
261+
IRBuilderBase &B, const TargetLibraryInfo *TLI,
262+
LibFunc NewFunc, uint8_t HotCold);
263+
Value *emitHotColdNewAligned(Type *RetTy, Value *Num, Value *Align,
264+
IRBuilderBase &B, const TargetLibraryInfo *TLI,
265+
LibFunc NewFunc, uint8_t HotCold);
266+
Value *emitHotColdNewAlignedNoThrow(Type *RetTy, Value *Num, Value *Align,
267+
Value *NoThrow, IRBuilderBase &B,
268268
const TargetLibraryInfo *TLI,
269269
LibFunc NewFunc, uint8_t HotCold);
270-
Value *emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B,
270+
Value *emitHotColdSizeReturningNew(Type *RetTy, Value *Num, IRBuilderBase &B,
271271
const TargetLibraryInfo *TLI,
272272
LibFunc NewFunc, uint8_t HotCold);
273-
Value *emitHotColdSizeReturningNewAligned(Value *Num, Value *Align,
274-
IRBuilderBase &B,
273+
Value *emitHotColdSizeReturningNewAligned(Type *RetTy, Value *Num,
274+
Value *Align, IRBuilderBase &B,
275275
const TargetLibraryInfo *TLI,
276276
LibFunc NewFunc, uint8_t HotCold);
277277
}

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,9 +2014,8 @@ struct DSEState {
20142014
return false;
20152015
IRBuilder<> IRB(Malloc);
20162016
Type *SizeTTy = Malloc->getArgOperand(0)->getType();
2017-
auto *Calloc =
2018-
emitCalloc(ConstantInt::get(SizeTTy, 1), Malloc->getArgOperand(0), IRB,
2019-
TLI, Malloc->getType()->getPointerAddressSpace());
2017+
auto *Calloc = emitCalloc(Malloc->getType(), ConstantInt::get(SizeTTy, 1),
2018+
Malloc->getArgOperand(0), IRB, TLI);
20202019
if (!Calloc)
20212020
return false;
20222021

0 commit comments

Comments
 (0)