Index: lib/Transforms/InstCombine/InstCombineCasts.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineCasts.cpp +++ lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -1820,6 +1820,10 @@ auto *LI = dyn_cast(IncValue); if (LI) { + // If the loaded value is used as the load address in the same + // instruction, bitcast is necessary to change the value type. + if (LI->getOperand(0) == &CI) + return nullptr; if (LI->hasOneUse() && LI->isSimple()) continue; // If a LoadInst has more than one use, changing the type of loaded Index: test/Transforms/InstCombine/pr27703.ll =================================================================== --- test/Transforms/InstCombine/pr27703.ll +++ test/Transforms/InstCombine/pr27703.ll @@ -0,0 +1,16 @@ +; RUN: opt < %s -instcombine -S | FileCheck %s + +define void @mem() { +bb: + br label %bb6 + +bb6: + %.0 = phi i8** [ undef, %bb ], [ %bc, %bb6 ] + %tmp = load i8*, i8** %.0, align 8 + %bc = bitcast i8* %tmp to i8** + br label %bb6 + +bb206: + ret void +; CHECK: bitcast +}