Skip to content

Commit 25c647a

Browse files
committed
[VPlan][LV] Fix invalid truncation in VPScalarIVStepsRecipe
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.
1 parent dfdc50b commit 25c647a

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,7 @@ void VPScalarIVStepsRecipe::execute(VPTransformState &State) {
21342134
Builder.CreateMul(StartIdx0, ConstantInt::get(StartIdx0->getType(),
21352135
getUnrollPart(*this)));
21362136
}
2137-
StartIdx0 = Builder.CreateTrunc(StartIdx0, IntStepTy);
2137+
StartIdx0 = Builder.CreateSExtOrTrunc(StartIdx0, IntStepTy);
21382138
}
21392139

21402140
if (!FirstLaneOnly && State.VF.isScalable()) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; RUN: opt -passes=loop-vectorize -S < %s > /dev/null
2+
; REQUIRES: asserts
3+
4+
target datalayout = "E-m:a-p:32:32-Fi32-i64:64-n32"
5+
target triple = "powerpc-ibm-aix7.2.0.0"
6+
7+
define void @__power_mod_NMOD_power_init(ptr %a, ptr %b, i32 %n) {
8+
entry:
9+
br label %loop_entry
10+
11+
loop_exit: ; preds = %loop_header
12+
br label %loop_entry
13+
14+
loop_entry: ; preds = %loop_exit, %entry
15+
%sum.0 = phi double [ 0.000000e+00, %entry ], [ %sum.1, %loop_exit ]
16+
%x = load double, ptr %a, align 8
17+
br label %loop_header
18+
19+
loop_header: ; preds = %loop_body, %loop_entry
20+
%sum.1 = phi double [ %sum.0, %loop_entry ], [ %sum.next, %loop_body ]
21+
%i = phi i32 [ 0, %loop_entry ], [ %i.next, %loop_body ]
22+
%cond = icmp sgt i32 %i, %n
23+
br i1 %cond, label %loop_exit, label %loop_body
24+
25+
loop_body: ; preds = %loop_header
26+
store double %sum.1, ptr %b, align 8
27+
%sum.next = fadd reassoc double %sum.1, %x
28+
%i.next = add i32 %i, 1
29+
br label %loop_header
30+
}
31+

0 commit comments

Comments
 (0)