In response to https://github.com/llvm/llvm-project/issues/56030
To be a bit more precise: LSR debug salvaging (DbgGatherSalvagableDVI) will call ScalarEvolution::getSCEV on the operands of @llvm.dbg.value. When doing this the results (SCEV -> Value and Value -> SCEV) are cached by the SCEV framework.
Later on when generating IR for the transformed loop LSRInstance::Expand ends up in SCEVExpander::FindValueInExprValueMap where the cached %inc = add i32 %0, 1 is found for SCEV (1 + %0) and that IR gets reused.
For the case where there is no @llvm.dbg.value in the input then %inc is not queried, not cached and wont be found when expanding. This results in a debug invariance issue.
If this is indeed the problem then I see two possible solutions. Either having SCEV forget about the query (and remove it from the cache) or some interface to prevent SCEV caching it in the first place.
Nit: extra space between were observed.