Skip some more superfluous bitcasts NOT using the DtoBitCast() helper

This commit is contained in:
Martin Kinkelin 2024-05-20 16:01:53 +02:00
parent d140f2a283
commit 7fa7f35b2a
9 changed files with 11 additions and 49 deletions

View file

@ -453,10 +453,7 @@ LLConstant *DtoConstArrayInitializer(ArrayInitializer *arrinit,
return gvar;
}
LLConstant *gep = DtoGEP(gvar->getValueType(), gvar, 0u, 0u);
gep = llvm::ConstantExpr::getBitCast(gvar, getPtrToType(llelemty));
return DtoConstSlice(DtoConstSize_t(arrlen), gep, arrty);
return DtoConstSlice(DtoConstSize_t(arrlen), gvar, arrty);
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -1490,11 +1490,7 @@ DValue *DtoSymbolAddress(const Loc &loc, Type *type, Declaration *decl) {
// typeinfo
if (TypeInfoDeclaration *tid = vd->isTypeInfoDeclaration()) {
Logger::println("TypeInfoDeclaration");
LLType *vartype = DtoType(type);
LLValue *m = DtoResolveTypeInfo(tid);
if (m->getType() != getPtrToType(vartype)) {
m = gIR->ir->CreateBitCast(m, vartype);
}
return new DImValue(type, m);
}
// special vtbl symbol, used by LDC as alias to the actual vtbl (with

View file

@ -136,10 +136,8 @@ LLFunction *build_module_reference_and_ctor(const char *moduleMangle,
// provide the default initializer
LLStructType *modulerefTy = DtoModuleReferenceType();
LLConstant *mrefvalues[] = {
LLConstant::getNullValue(modulerefTy->getContainedType(0)),
llvm::ConstantExpr::getBitCast(moduleinfo,
modulerefTy->getContainedType(1))};
LLConstant *mrefvalues[] = {LLConstant::getNullValue(getVoidPtrType()),
moduleinfo};
LLConstant *thismrefinit = LLConstantStruct::get(
modulerefTy, llvm::ArrayRef<LLConstant *>(mrefvalues));

View file

@ -69,8 +69,6 @@ struct G2StackAnalysis {
void EmitMemSet(IRBuilder<> &B, Value *Dst, Value *Val, Value *Len,
const G2StackAnalysis &A) {
Dst = B.CreateBitCast(Dst, PointerType::getUnqual(B.getInt8Ty()));
MaybeAlign Align(1);
auto CS = B.CreateMemSet(Dst, Val, Len, Align, false /*isVolatile*/);
@ -197,9 +195,7 @@ Value* ArrayFI::promote(CallBase *CB, IRBuilder<> &B, const G2StackAnalysis &A)
if (ReturnType == ReturnType::Array) {
Value *arrStruct = llvm::UndefValue::get(CB->getType());
arrStruct = Builder.CreateInsertValue(arrStruct, arrSize, 0);
Value *memPtr =
Builder.CreateBitCast(alloca, PointerType::getUnqual(B.getInt8Ty()));
arrStruct = Builder.CreateInsertValue(arrStruct, memPtr, 1);
arrStruct = Builder.CreateInsertValue(arrStruct, alloca, 1);
return arrStruct;
}
@ -284,7 +280,7 @@ Value* UntypedMemoryFI::promote(CallBase *CB, IRBuilder<> &B, const G2StackAnaly
AllocaInst *alloca =
B.CreateAlloca(Ty, count, ".nongc_mem"); // FIXME: align?
return B.CreateBitCast(alloca, CB->getType());
return alloca;
}
//}
@ -454,9 +450,7 @@ bool GarbageCollect2Stack::run(Function &F, std::function<DominatorTree& ()> get
// Make sure the type is the same as it was before, and replace all
// uses of the runtime call with the alloca.
if (newVal->getType() != CB->getType()) {
newVal = Builder.CreateBitCast(newVal, CB->getType());
}
assert(newVal->getType() == CB->getType());
static_cast<Instruction *>(CB)->replaceAllUsesWith(newVal);
RemoveCall(CB, A);

View file

@ -51,18 +51,12 @@ Value *LibCallOptimization::OptimizeCall(CallInst *CI, bool &Changed, const Data
return CallOptimizer(CI->getCalledFunction(), CI, B);
}
/// CastToCStr - Return V if it is an i8*, otherwise cast it to i8*.
Value *LibCallOptimization::CastToCStr(Value *V, IRBuilder<> &B) {
return B.CreateBitCast(V, PointerType::getUnqual(B.getInt8Ty()), "cstr");
}
/// EmitMemCpy - Emit a call to the memcpy function to the builder. This always
/// expects that the size has type 'intptr_t' and Dst/Src are pointers.
Value *LibCallOptimization::EmitMemCpy(Value *Dst, Value *Src, Value *Len,
unsigned Align, IRBuilder<> &B) {
auto A = llvm::MaybeAlign(Align);
return B.CreateMemCpy(CastToCStr(Dst, B), A, CastToCStr(Src, B), A, Len,
false);
return B.CreateMemCpy(Dst, A, Src, A, Len, false);
}
//===----------------------------------------------------------------------===//

View file

@ -18,9 +18,6 @@ protected:
llvm::AliasAnalysis *AA;
llvm::LLVMContext *Context;
/// CastToCStr - Return V if it is an i8*, otherwise cast it to i8*.
llvm::Value *CastToCStr(llvm::Value *V, llvm::IRBuilder<> &B);
/// EmitMemCpy - Emit a call to the memcpy function to the builder. This
/// always expects that the size has type 'intptr_t' and Dst/Src are pointers.
llvm::Value *EmitMemCpy(llvm::Value *Dst, llvm::Value *Src, llvm::Value *Len, unsigned Align,

View file

@ -909,10 +909,8 @@ void CodeGenPGO::emitCounterIncrement(const RootObject *S) const {
assert(counter_it != (*RegionCounterMap).end() &&
"Statement not found in PGO counter map!");
unsigned counter = counter_it->second;
auto *I8PtrTy = getVoidPtrType();
gIR->ir->CreateCall(GET_INTRINSIC_DECL(instrprof_increment),
{llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
gIR->ir->getInt64(FunctionHash),
{FuncNameVar, gIR->ir->getInt64(FunctionHash),
gIR->ir->getInt32(NumRegionCounters),
gIR->ir->getInt32(counter)});
}
@ -1117,10 +1115,8 @@ void CodeGenPGO::valueProfile(uint32_t valueKind, llvm::Instruction *valueSite,
if (ptrCastNeeded)
value = gIR->ir->CreatePtrToInt(value, gIR->ir->getInt64Ty());
auto *i8PtrTy = getVoidPtrType();
llvm::Value *Args[5] = {
llvm::ConstantExpr::getBitCast(FuncNameVar, i8PtrTy),
gIR->ir->getInt64(FunctionHash), value, gIR->ir->getInt32(valueKind),
llvm::Value *Args[5] = {FuncNameVar, gIR->ir->getInt64(FunctionHash), value,
gIR->ir->getInt32(valueKind),
gIR->ir->getInt32(NumValueSites[valueKind])};
gIR->ir->CreateCall(GET_INTRINSIC_DECL(instrprof_value_profile), Args);

View file

@ -262,14 +262,6 @@ public:
Logger::println("Loading value for return");
returnValue = DtoLoad(funcType->getReturnType(), returnValue);
}
// can happen for classes
if (returnValue->getType() != funcType->getReturnType()) {
returnValue =
irs->ir->CreateBitCast(returnValue, funcType->getReturnType());
IF_LOG Logger::cout()
<< "return value after cast: " << *returnValue << '\n';
}
}
} else {
// no return value expression means it's a void function.

View file

@ -51,7 +51,6 @@ void LocalVariableLifetimeAnnotator::addLocalVariable(llvm::Value *address,
scopes.back().variables.emplace_back(size, address);
// Emit lifetime start
address = irs.ir->CreateBitCast(address, allocaType);
irs.CreateCallOrInvoke(getLLVMLifetimeStartFn(), {size, address}, "",
true /*nothrow*/);
}
@ -65,7 +64,6 @@ void LocalVariableLifetimeAnnotator::popScope() {
auto size = var.first;
auto address = var.second;
address = irs.ir->CreateBitCast(address, allocaType);
assert(address);
irs.CreateCallOrInvoke(getLLVMLifetimeEndFn(), {size, address}, "",