Skip to content

Commit 54fc536

Browse files
committed
[LV] Fix crash in uncountable exit with side effects checking
Fixes an ICE reported on PR #145663, as an assert was found to be reachable with a specific combination of unreachable blocks.
1 parent 40d8af8 commit 54fc536

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,11 +1903,12 @@ bool LoopVectorizationLegality::canUncountableExitConditionLoadBeMoved(
19031903
SafetyInfo.computeLoopSafetyInfo(TheLoop);
19041904
// We need to know that load will be executed before we can hoist a
19051905
// copy out to run just before the first iteration.
1906-
// FIXME: Currently, other restrictions prevent us from reaching this point
1907-
// with a loop where the uncountable exit condition is determined
1908-
// by a conditional load.
1909-
assert(SafetyInfo.isGuaranteedToExecute(*Load, DT, TheLoop) &&
1910-
"Unhandled control flow in uncountable exit loop with side effects");
1906+
if (!SafetyInfo.isGuaranteedToExecute(*Load, DT, TheLoop)) {
1907+
reportVectorizationFailure(
1908+
"Load for uncountable exit not guaranteed to execute",
1909+
"ConditionalUncountableExitLoad", ORE, TheLoop);
1910+
return false;
1911+
}
19111912

19121913
// Prohibit any potential aliasing with any instruction in the loop which
19131914
// might store to memory.

llvm/test/Transforms/LoopVectorize/early_exit_store_legality.ll

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,5 +602,40 @@ exit:
602602
ret void
603603
}
604604

605+
;; ICE was caused by assert for the load used in the uncountable exit condition
606+
;; being guaranteed to execute.
607+
@e = external addrspace(21) global [4 x i8]
608+
define void @crash_conditional_load_for_uncountable_exit() {
609+
; CHECK-LABEL: LV: Checking a loop in 'crash_conditional_load_for_uncountable_exit'
610+
; CHECK: LV: Not vectorizing: Load for uncountable exit not guaranteed to execute.
611+
entry:
612+
br label %cont
613+
614+
handler.out_of_bounds:
615+
unreachable
616+
617+
cont:
618+
%h.06 = phi i64 [ 0, %entry ], [ %inc, %a.exit ]
619+
%arrayidx = getelementptr i8, ptr addrspace(21) @e, i64 %h.06
620+
br i1 false, label %cont1, label %handler.type_mismatch
621+
622+
handler.type_mismatch:
623+
unreachable
624+
625+
cont1:
626+
%0 = load i8, ptr addrspace(21) %arrayidx, align 1
627+
store i16 0, ptr null, align 2
628+
%cmp.not.i.i = icmp eq i8 %0, 0
629+
br i1 %cmp.not.i.i, label %a.exit, label %if.then.i.i
630+
631+
if.then.i.i:
632+
unreachable
633+
634+
a.exit:
635+
%inc = add i64 %h.06, 1
636+
br i1 true, label %handler.out_of_bounds, label %cont
637+
}
638+
639+
605640
declare void @init_mem(ptr, i64);
606641
declare i64 @get_an_unknown_offset();

0 commit comments

Comments
 (0)