Index: llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp =================================================================== --- llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp +++ llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp @@ -1634,7 +1634,7 @@ // If the cast is observable, and it is used by a widening instruction (e.g., // uaddl, saddw, etc.), it may be free. - if (I && I->hasOneUser()) { + if (I && I->hasOneUser() && !isa(Src)) { auto *SingleUser = cast(*I->user_begin()); SmallVector Operands(SingleUser->operand_values()); if (isWideningInstruction(Dst, SingleUser->getOpcode(), Operands)) { Index: llvm/test/Analysis/CostModel/AArch64/sve-widening-instruction.ll =================================================================== --- llvm/test/Analysis/CostModel/AArch64/sve-widening-instruction.ll +++ llvm/test/Analysis/CostModel/AArch64/sve-widening-instruction.ll @@ -20,8 +20,8 @@ define @widening_v8i16( %in1, %in2) { ; CHECK-LABEL: 'widening_v8i16' -; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %in1.ext = zext %in2 to -; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %in2.ext = zext %in2 to +; CHECK-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %in1.ext = zext %in2 to +; CHECK-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %in2.ext = zext %in2 to ; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %in.add = add %in1.ext, %in2.ext ; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret %in.add ;