Skip to content

Commit

Permalink
SimplifyLibCalls: Use default globals address space when building new…
Browse files Browse the repository at this point in the history
… global strings. (llvm#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.
  • Loading branch information
resistor authored Dec 5, 2024
1 parent 6f21401 commit cfa582e
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 111 deletions.
32 changes: 16 additions & 16 deletions llvm/include/llvm/Transforms/Utils/BuildLibCalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,32 +246,32 @@ namespace llvm {
const DataLayout &DL, const TargetLibraryInfo *TLI);

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

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

/// Emit a call to the hot/cold operator new function.
Value *emitHotColdNew(Value *Num, IRBuilderBase &B,
Value *emitHotColdNew(Type *RetTy, Value *Num, IRBuilderBase &B,
const TargetLibraryInfo *TLI, LibFunc NewFunc,
uint8_t HotCold);
Value *emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B,
const TargetLibraryInfo *TLI, LibFunc NewFunc,
uint8_t HotCold);
Value *emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B,
const TargetLibraryInfo *TLI, LibFunc NewFunc,
uint8_t HotCold);
Value *emitHotColdNewAlignedNoThrow(Value *Num, Value *Align, Value *NoThrow,
IRBuilderBase &B,
Value *emitHotColdNewNoThrow(Type *RetTy, Value *Num, Value *NoThrow,
IRBuilderBase &B, const TargetLibraryInfo *TLI,
LibFunc NewFunc, uint8_t HotCold);
Value *emitHotColdNewAligned(Type *RetTy, Value *Num, Value *Align,
IRBuilderBase &B, const TargetLibraryInfo *TLI,
LibFunc NewFunc, uint8_t HotCold);
Value *emitHotColdNewAlignedNoThrow(Type *RetTy, Value *Num, Value *Align,
Value *NoThrow, IRBuilderBase &B,
const TargetLibraryInfo *TLI,
LibFunc NewFunc, uint8_t HotCold);
Value *emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B,
Value *emitHotColdSizeReturningNew(Type *RetTy, Value *Num, IRBuilderBase &B,
const TargetLibraryInfo *TLI,
LibFunc NewFunc, uint8_t HotCold);
Value *emitHotColdSizeReturningNewAligned(Value *Num, Value *Align,
IRBuilderBase &B,
Value *emitHotColdSizeReturningNewAligned(Type *RetTy, Value *Num,
Value *Align, IRBuilderBase &B,
const TargetLibraryInfo *TLI,
LibFunc NewFunc, uint8_t HotCold);
}
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2014,9 +2014,8 @@ struct DSEState {
return false;
IRBuilder<> IRB(Malloc);
Type *SizeTTy = Malloc->getArgOperand(0)->getType();
auto *Calloc =
emitCalloc(ConstantInt::get(SizeTTy, 1), Malloc->getArgOperand(0), IRB,
TLI, Malloc->getType()->getPointerAddressSpace());
auto *Calloc = emitCalloc(Malloc->getType(), ConstantInt::get(SizeTTy, 1),
Malloc->getArgOperand(0), IRB, TLI);
if (!Calloc)
return false;

Expand Down
Loading

0 comments on commit cfa582e

Please sign in to comment.