Skip to content

Commit

Permalink
Correctly handle uncanonicalized addrspacecasts.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Mar 15, 2024
1 parent e3c28a5 commit cdaeac9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/llvm-remove-addrspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,14 @@ bool RemoveNoopAddrSpaceCasts(Function *F)
LLVM_DEBUG(
dbgs() << "Removing noop address space cast:\n"
<< I << "\n");
ASC->replaceAllUsesWith(ASC->getOperand(0));
if (ASC->getType() == ASC->getOperand(0)->getType()) {
ASC->replaceAllUsesWith(ASC->getOperand(0));
} else {
// uncanonicalized addrspacecast; demote to bitcast
llvm::IRBuilder<> builder(ASC);
auto BC = builder.CreateBitCast(ASC->getOperand(0), ASC->getType());
ASC->replaceAllUsesWith(BC);
}
NoopCasts.push_back(ASC);
}
}
Expand Down

0 comments on commit cdaeac9

Please sign in to comment.