-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[VPlan][LV] Fix invalid truncation in VPScalarIVStepsRecipe #137832
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
Conversation
Replace CreateTrunc with CreateSExtOrTrunc in VPScalarIVStepsRecipe to safely handle type conversion. This prevents assertion failures from invalid truncation when StartIdx0 has a smaller integer type than IntStepTy. The assertion was introduced by commit 783a846.
@llvm/pr-subscribers-backend-powerpc @llvm/pr-subscribers-llvm-transforms Author: Maryam Moghadas (maryammo) ChangesReplace CreateTrunc with CreateSExtOrTrunc in VPScalarIVStepsRecipe to safely handle type conversion. This prevents assertion failures from invalid truncation when StartIdx0 has a smaller integer type than IntStepTy. The assertion was introduced by commit 783a846. Full diff: https://github.com/llvm/llvm-project/pull/137832.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 75d056026025a..6ca43eec63dd4 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -2134,7 +2134,7 @@ void VPScalarIVStepsRecipe::execute(VPTransformState &State) {
Builder.CreateMul(StartIdx0, ConstantInt::get(StartIdx0->getType(),
getUnrollPart(*this)));
}
- StartIdx0 = Builder.CreateTrunc(StartIdx0, IntStepTy);
+ StartIdx0 = Builder.CreateSExtOrTrunc(StartIdx0, IntStepTy);
}
if (!FirstLaneOnly && State.VF.isScalable()) {
diff --git a/llvm/test/Transforms/LoopVectorize/PowerPC/vplan-scalarivsext-crash.ll b/llvm/test/Transforms/LoopVectorize/PowerPC/vplan-scalarivsext-crash.ll
new file mode 100644
index 0000000000000..66b54a29b913c
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/PowerPC/vplan-scalarivsext-crash.ll
@@ -0,0 +1,31 @@
+; RUN: opt -passes=loop-vectorize -S < %s > /dev/null
+; REQUIRES: asserts
+
+target datalayout = "E-m:a-p:32:32-Fi32-i64:64-n32"
+target triple = "powerpc-ibm-aix7.2.0.0"
+
+define void @__power_mod_NMOD_power_init(ptr %a, ptr %b, i32 %n) {
+entry:
+ br label %loop_entry
+
+loop_exit: ; preds = %loop_header
+ br label %loop_entry
+
+loop_entry: ; preds = %loop_exit, %entry
+ %sum.0 = phi double [ 0.000000e+00, %entry ], [ %sum.1, %loop_exit ]
+ %x = load double, ptr %a, align 8
+ br label %loop_header
+
+loop_header: ; preds = %loop_body, %loop_entry
+ %sum.1 = phi double [ %sum.0, %loop_entry ], [ %sum.next, %loop_body ]
+ %i = phi i32 [ 0, %loop_entry ], [ %i.next, %loop_body ]
+ %cond = icmp sgt i32 %i, %n
+ br i1 %cond, label %loop_exit, label %loop_body
+
+loop_body: ; preds = %loop_header
+ store double %sum.1, ptr %b, align 8
+ %sum.next = fadd reassoc double %sum.1, %x
+ %i.next = add i32 %i, 1
+ br label %loop_header
+}
+
|
llvm/test/Transforms/LoopVectorize/PowerPC/vplan-scalarivsext-crash.ll
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,31 @@ | |||
; RUN: opt -passes=loop-vectorize -disable-output -S < %s | |||
; REQUIRES: asserts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the test to check the output as @lukel97 suggested, we should check we get the expected result. You then can also remove REQUIRES: asserts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
loop_exit: ; preds = %loop_header | ||
br label %loop_entry | ||
|
||
loop_entry: ; preds = %loop_exit, %entry | ||
%sum.0 = phi double [ 0.000000e+00, %entry ], [ %sum.1, %loop_exit ] | ||
%x = load double, ptr %a, align 8 | ||
br label %loop_header |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the loop nest or can this simply be a single loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the test to use a single loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks.
Please add something like Fixes https://github.com/llvm/llvm-project/issues/137185
to the PR description to make sure the issue is closed when this lands.
;. | ||
; CHECK: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]]} | ||
; CHECK: [[META1]] = !{!"llvm.loop.isvectorized", i32 1} | ||
; CHECK: [[META2]] = !{!"llvm.loop.unroll.runtime.disable"} | ||
; CHECK: [[LOOP3]] = distinct !{[[LOOP3]], [[META1]]} | ||
;. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can use --check-globals=none
to remove those uninteresting checks
) Replace CreateTrunc with CreateSExtOrTrunc in VPScalarIVStepsRecipe to safely handle type conversion. This prevents assertion failures from invalid truncation when StartIdx0 has a smaller integer type than IntStepTy. The assertion was introduced by commit 783a846. Fixes llvm#137185
Replace CreateTrunc with CreateSExtOrTrunc in VPScalarIVStepsRecipe to safely handle type conversion. This prevents assertion failures from invalid truncation when StartIdx0 has a smaller integer type than IntStepTy. The assertion was introduced by commit 783a846.
Fixes #137185