fix infinite loop with multi-exit loop and unroll=1
MODIFY
ir/function.cpp
ir/function.cpp
@@ -567,7 +567,7 @@ void Function::unroll(unsigned k) {
for (auto &[user, user_bb] : I->second) {
// users inside the loop have been patched already
- if (vmap.count(user))
+ if (bbmap.count(user_bb))
continue;
if (auto phi = dynamic_cast<Phi*>(user)) {

ADD
tests/alive-tv/loops/multi-exit-fail.srctgt.ll
+; TEST-ARGS: -src-unroll=1 -tgt-unroll=1
+; ERROR: Value mismatch
+
+define i32 @src() {
+entry:
+ br label %for.cond
+
+for.cond:
+ %i = phi i32 [ 0, %entry ], [ %inc1, %for.body ]
+ %r = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+ switch i32 %i, label %for.body [
+ i32 1, label %for.end
+ i32 2, label %for.end
+ i32 3, label %for.end
+ ]
+
+for.body:
+ %inc = add i32 %r, 2
+ %inc1 = add i32 %i, 1
+ br label %for.cond
+
+for.end:
+ ret i32 %r
+}
+
+define i32 @tgt() {
+ ret i32 4
+}

ADD
tests/alive-tv/loops/multi-exit.srctgt.ll
+; TEST-ARGS: -src-unroll=2 -tgt-unroll=2
+
+define i32 @src() {
+entry:
+ br label %for.cond
+
+for.cond:
+ %i = phi i32 [ 0, %entry ], [ %inc1, %for.body ]
+ %r = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+ switch i32 %i, label %for.body [
+ i32 2, label %for.end
+ i32 3, label %for.end
+ ]
+
+for.body:
+ %inc = add i32 %r, 2
+ %inc1 = add i32 %i, 1
+ br label %for.cond
+
+for.end:
+ ret i32 %r
+}
+
+define i32 @tgt() {
+ ret i32 4
+}

fix infinite loop with multi-exit loop and unroll=1