[llvm] Add debug location to strlen in LoopIdiomRecognize pass (PR #140164)

Amy Huang via llvm-commits llvm-commits at lists.llvm.org
Fri May 16 14:12:39 PDT 2025


================
@@ -612,3 +612,51 @@ while.end:
   ret i64 %sub.ptr.sub
 }
 
+define i64 @valid_basic_strlen_with_dbg(ptr %str) {
+; CHECK-LABEL: define i64 @valid_basic_strlen_with_dbg(
+; CHECK-SAME: ptr [[STR:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*]]:
+; CHECK-NEXT:    [[STRLEN:%.*]] = call i64 @strlen(ptr [[STR]]), !dbg !{{[0-9]+}}
----------------
amykhuang wrote:

Whoops, yeah, I put in the general match because opt was reordering the debug info metadata, but I just reordered it to the "correct" order.

Not sure about the other instructions; they look unchanged so I assume the debug info would remain unchangd as well. Looks like in this particular test case only the compare instruction got replaced with a strlen call. will add the code author too, just realized the change is fairly recent. 



https://github.com/llvm/llvm-project/pull/140164


More information about the llvm-commits mailing list