Index: llvm/lib/CodeGen/TypePromotion.cpp =================================================================== --- llvm/lib/CodeGen/TypePromotion.cpp +++ llvm/lib/CodeGen/TypePromotion.cpp @@ -551,8 +551,11 @@ } // Don't insert a trunc for a zext which can still legally promote. + // Nor insert a trunc for a zext with the same input type as output, this + // was a zext that was part of a promotion mutation and will be removed + // after. if (auto ZExt = dyn_cast(I)) - if (ZExt->getType()->getScalarSizeInBits() > PromotedWidth) + if (ZExt->getType()->getScalarSizeInBits() >= PromotedWidth) continue; // Now handle the others. Index: llvm/test/Transforms/TypePromotion/AArch64/phi-zext-gep.ll =================================================================== --- llvm/test/Transforms/TypePromotion/AArch64/phi-zext-gep.ll +++ llvm/test/Transforms/TypePromotion/AArch64/phi-zext-gep.ll @@ -24,7 +24,6 @@ ; CHECK-NEXT: br label [[FOR_END]] ; CHECK: for.end: ; CHECK-NEXT: [[TAG_0_IN_LCSSA:%.*]] = phi i32 [ [[TMP0]], [[ENTRY:%.*]] ], [ [[TMP1]], [[FOR_END_LOOPEXIT]] ] -; CHECK-NEXT: [[TMP2:%.*]] = trunc i32 [[TAG_0_IN_LCSSA]] to i8 ; CHECK-NEXT: ret i32 [[TAG_0_IN_LCSSA]] ; entry: