From 2593167b92dd2d27849e8bc331db2072a9b4bd7f Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Mon, 4 Dec 2023 11:21:55 -0500 Subject: [PATCH] Block hoisting bitcasts over non-integral ascast (#23) --- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index a9a930555b3c6..5f09f59cff7d6 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -2906,8 +2906,10 @@ Instruction *InstCombinerImpl::visitAddrSpaceCast(AddrSpaceCastInst &CI) { Value *Src = CI.getOperand(0); PointerType *SrcTy = cast(Src->getType()->getScalarType()); PointerType *DestTy = cast(CI.getType()->getScalarType()); + bool isni = DL.isNonIntegralAddressSpace(SrcTy->getAddressSpace()) || + DL.isNonIntegralAddressSpace(DestTy->getAddressSpace()); - if (!SrcTy->hasSameElementTypeAs(DestTy)) { + if (!SrcTy->hasSameElementTypeAs(DestTy) && !isni) { Type *MidTy = PointerType::getWithSamePointeeType(DestTy, SrcTy->getAddressSpace()); // Handle vectors of pointers.