Bug type: crash
Component: LoopStrengthReduce
Bug location: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp: SalvageDVI
Issue title: llc: ../lib/Transforms/Scalar/LoopStrengthReduce.cpp:6630: [...] Assertion `!LocationOps.empty() && "Expected the location ops to contain the IV."' failed.
Labels: debuginfo
crash
llvm:transforms
Reported by: mikaelholmen

llvm commit: 82e594a022d
Reproduce with: ```llc bbi-99605.ll -o /dev/null```
Result:
```
llc: ../lib/Transforms/Scalar/LoopStrengthReduce.cpp:6630: void (anonymous namespace)::SCEVDbgValueBuilder::appendToVectors(SmallVectorImpl<uint64_t> &, SmallVectorImpl<llvm::Value *> &): Assertion `!LocationOps.empty() && "Expected the location ops to contain the IV."' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: build-all/bin/llc bbi-99605.ll -o /dev/null
1.	Running pass 'Function Pass Manager' on module 'bbi-99605.ll'.
2.	Running pass 'Loop Pass Manager' on function '@main'
3.	Running pass 'Loop Strength Reduction' on basic block '%for.cond29'
 #0 0x000055e150599557 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (build-all/bin/llc+0x6dee557)
 #1 0x000055e1505970be llvm::sys::RunSignalHandlers() (build-all/bin/llc+0x6dec0be)
 #2 0x000055e150599bff SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f66b410bcf0 __restore_rt (/lib64/libpthread.so.0+0x12cf0)
 #4 0x00007f66b1cc4acf raise (/lib64/libc.so.6+0x4eacf)
 #5 0x00007f66b1c97ea5 abort (/lib64/libc.so.6+0x21ea5)
 #6 0x00007f66b1c97d79 _nl_load_domain.cold.0 (/lib64/libc.so.6+0x21d79)
 #7 0x00007f66b1cbd426 (/lib64/libc.so.6+0x47426)
 #8 0x000055e15005db21 (build-all/bin/llc+0x68b2b21)
 #9 0x000055e15005c0c3 SalvageDVI(llvm::Loop*, llvm::ScalarEvolution&, llvm::PHINode*, (anonymous namespace)::DVIRecoveryRec&, llvm::SCEV const*, (anonymous namespace)::SCEVDbgValueBuilder) LoopStrengthReduce.cpp:0:0
#10 0x000055e15002dca8 ReduceLoopStrength(llvm::Loop*, llvm::IVUsers&, llvm::ScalarEvolution&, llvm::DominatorTree&, llvm::LoopInfo&, llvm::TargetTransformInfo const&, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::MemorySSA*) LoopStrengthReduce.cpp:0:0
#11 0x000055e15005e7e8 (anonymous namespace)::LoopStrengthReduce::runOnLoop(llvm::Loop*, llvm::LPPassManager&) LoopStrengthReduce.cpp:0:0
#12 0x000055e14f26f0f9 llvm::LPPassManager::runOnFunction(llvm::Function&) (build-all/bin/llc+0x5ac40f9)
#13 0x000055e14fba9e38 llvm::FPPassManager::runOnFunction(llvm::Function&) (build-all/bin/llc+0x63fee38)
#14 0x000055e14fbb2171 llvm::FPPassManager::runOnModule(llvm::Module&) (build-all/bin/llc+0x6407171)
#15 0x000055e14fbaa8b5 llvm::legacy::PassManagerImpl::run(llvm::Module&) (build-all/bin/llc+0x63ff8b5)
#16 0x000055e14d988be8 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#17 0x000055e14d98626d main (build-all/bin/llc+0x41db26d)
#18 0x00007f66b1cb0d85 __libc_start_main (/lib64/libc.so.6+0x3ad85)
#19 0x000055e14d9822ee _start (build-all/bin/llc+0x41d72ee)
Abort (core dumped)
```
The input contains the new debug info:
```#dbg_value(i128 %l_995.0, !4, !DIExpression(), !9)```

[bbi-99605.ll.gz](https://github.com/user-attachments/files/17189125/bbi-99605.ll.gz)


Comments: author: OCHyams
body: Thanks for the small reproducer. That is fixed in #110979 - this PR just avoids us crash/asserting when a salvage attempt is made with an offset over 64 bits wide and poisons the dbg record instead. I didn't look into whether we could theoretically or practically salvage it.

n.b., this case was broken with debug intrinsics too, not just the new debug record format.

Fix patch:
commit 7506872afc6c1cc7556eed5128a2030b6eb8ca29
Author: Orlando Cazalet-Hyams <orlando.hyams@sony.com>
Date:   Thu Oct 3 11:47:08 2024 +0100

    [DebugInfo][LSR] Fix assertion failure salvaging IV with offset > 64 bits wide (#110979)
    
    Fixes #110494

diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index f69db57c25ed..575395eda1c5 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -6870,6 +6870,8 @@ static bool SalvageDVI(llvm::Loop *L, ScalarEvolution &SE,
             SE.computeConstantDifference(DVIRec.SCEVs[i], SCEVInductionVar)) {
       if (Offset->getSignificantBits() <= 64)
         SalvageExpr->createOffsetExpr(Offset->getSExtValue(), LSRInductionVar);
+      else
+        return false;
     } else if (!SalvageExpr->createIterCountExpr(DVIRec.SCEVs[i], IterCountExpr,
                                                  SE))
       return false;


Regression tests:
file: llvm/test/Transforms/LoopStrengthReduce/debuginfo-scev-salvage-large-width.ll
commands: opt -S -loop-reduce %s
tests: test_name: main
test_body: define i16 @main() {
entry:
  br label %for.cond29

for.cond29:                                       ; preds = %for.body32, %entry
  %il_1000.0 = phi i128 [ 0, %entry ], [ %inc72, %for.body32 ]
  %l_995.0 = phi i128 [ 4704496199548239085565, %entry ], [ %inc70, %for.body32 ]
    #dbg_value(i128 %l_995.0, !4, !DIExpression(), !9)
  %cmp30 = icmp slt i128 %il_1000.0, 0
  br i1 %cmp30, label %for.body32, label %for.cond.cleanup31

for.cond.cleanup31:                               ; preds = %for.cond29
  ret i16 0

for.body32:                                       ; preds = %for.cond29
  %inc70 = add i128 %l_995.0, 1
  %inc72 = add i128 %il_1000.0, 1
  br label %for.cond29
}

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3}

!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2, globals: !2, splitDebugInlining: false, nameTableKind: None)
!1 = !DIFile(filename: "foo.c", directory: "/tmp")
!2 = !{}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!4 = !DILocalVariable(name: "l_995", scope: !5, file: !1, line: 414, type: !7)
!5 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 397, type: !6, scopeLine: 398, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
!6 = !DISubroutineType(types: !2)
!7 = !DIDerivedType(tag: DW_TAG_typedef, name: "__uint128_t", file: !1, baseType: !8)
!8 = !DIBasicType(name: "unsigned __int128", size: 128, encoding: DW_ATE_unsigned)
!9 = !DILocation(line: 0, scope: !5)