-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[DebugInfo][IndVarSimplify] Propagate source loc when simplifying rem #135399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When IndVarSimplify simplifies a rem of the induction variable to a cmp and select, only the select currently receives the rem's source location; this patch propagates it to the select as well. Found using llvm#107279.
@llvm/pr-subscribers-llvm-transforms Author: Stephen Tozer (SLTozer) ChangesWhen IndVarSimplify simplifies a rem of the induction variable to a cmp and select, only the select currently receives the rem's source location; this patch propagates it to the cmp as well. Found using #107279. Full diff: https://github.com/llvm/llvm-project/pull/135399.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
index 5a76bec017655..03dbf9513d140 100644
--- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
@@ -350,6 +350,7 @@ void SimplifyIndvar::replaceRemWithNumeratorOrZero(BinaryOperator *Rem) {
auto *T = Rem->getType();
auto *N = Rem->getOperand(0), *D = Rem->getOperand(1);
ICmpInst *ICmp = new ICmpInst(Rem->getIterator(), ICmpInst::ICMP_EQ, N, D);
+ ICmp->setDebugLoc(Rem->getDebugLoc());
SelectInst *Sel =
SelectInst::Create(ICmp, ConstantInt::get(T, 0), N, "iv.rem", Rem->getIterator());
Rem->replaceAllUsesWith(Sel);
diff --git a/llvm/test/Transforms/IndVarSimplify/debugloc-rem-subst.ll b/llvm/test/Transforms/IndVarSimplify/debugloc-rem-subst.ll
new file mode 100644
index 0000000000000..121eec75c1b3c
--- /dev/null
+++ b/llvm/test/Transforms/IndVarSimplify/debugloc-rem-subst.ll
@@ -0,0 +1,59 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -p=indvars -S | FileCheck %s
+
+;; When that when IndVarSimplify simplifies the rem to a cmp and select, we
+;; propagate the rem's source location to both the new instructions.
+
+define i32 @widget() !dbg !5 {
+; CHECK-LABEL: define i32 @widget(
+; CHECK-SAME: ) !dbg [[DBG5:![0-9]+]] {
+; CHECK-NEXT: [[BB:.*:]]
+; CHECK-NEXT: br label %[[BB1:.*]]
+; CHECK: [[BB1_LOOPEXIT:.*]]:
+; CHECK-NEXT: br label %[[BB1]]
+; CHECK: [[BB1]]:
+; CHECK-NEXT: br label %[[BB2:.*]]
+; CHECK: [[BB2]]:
+; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ 0, %[[BB1]] ], [ [[ADD:%.*]], %[[BB2]] ]
+; CHECK-NEXT: [[ADD]] = add nuw nsw i32 1, [[PHI]]
+; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i32 [[ADD]], 3, !dbg [[DBG8:![0-9]+]]
+; CHECK-NEXT: [[IV_REM:%.*]] = select i1 [[TMP0]], i32 0, i32 [[ADD]], !dbg [[DBG8]]
+; CHECK-NEXT: [[ZEXT:%.*]] = zext i32 [[IV_REM]] to i64
+; CHECK-NEXT: br i1 false, label %[[BB2]], label %[[BB1_LOOPEXIT]]
+;
+bb:
+ br label %bb1
+
+bb1: ; preds = %bb2, %bb
+ br label %bb2
+
+bb2: ; preds = %bb2, %bb1
+ %phi = phi i32 [ 0, %bb1 ], [ %add, %bb2 ]
+ %add = add i32 1, %phi
+ %urem = urem i32 %add, 3, !dbg !8
+ %zext = zext i32 %urem to i64
+ %icmp = icmp ult i32 %phi, 2
+ br i1 %icmp, label %bb2, label %bb1
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.debugify = !{!2, !3}
+!llvm.module.flags = !{!4}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
+!1 = !DIFile(filename: "llvm/test/Transforms/IndVarSimplify/debugloc-rem-subst.ll", directory: "/")
+!2 = !{i32 8}
+!3 = !{i32 0}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = distinct !DISubprogram(name: "widget", linkageName: "widget", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
+!6 = !DISubroutineType(types: !7)
+!7 = !{}
+!8 = !DILocation(line: 1, column: 1, scope: !5)
+;.
+; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C, file: [[META1:![0-9]+]], producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
+; CHECK: [[META1]] = !DIFile(filename: "llvm/test/Transforms/IndVarSimplify/debugloc-rem-subst.ll", directory: {{.*}})
+; CHECK: [[DBG5]] = distinct !DISubprogram(name: "widget", linkageName: "widget", scope: null, file: [[META1]], line: 1, type: [[META6:![0-9]+]], scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]])
+; CHECK: [[META6]] = !DISubroutineType(types: [[META7:![0-9]+]])
+; CHECK: [[META7]] = !{}
+; CHECK: [[DBG8]] = !DILocation(line: 1, column: 1, scope: [[DBG5]])
+;.
|
OCHyams
approved these changes
Apr 17, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
…llvm#135399) When IndVarSimplify simplifies a rem of the induction variable to a cmp and select, only the select currently receives the rem's source location; this patch propagates it to the cmp as well. Found using llvm#107279.
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
…llvm#135399) When IndVarSimplify simplifies a rem of the induction variable to a cmp and select, only the select currently receives the rem's source location; this patch propagates it to the cmp as well. Found using llvm#107279.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When IndVarSimplify simplifies a rem of the induction variable to a cmp and select, only the select currently receives the rem's source location; this patch propagates it to the cmp as well.
Found using #107279.