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 18, 2024
1 parent 481e445 commit 06276d1
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 06276d1

Please sign in to comment.