From 6381cd9173f77b4807332374b09172866d51363b Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Mon, 30 Oct 2023 14:40:56 +0000 Subject: [PATCH] fix #951: false-positive condition for loop sinks doesn't take nonreturn functions into account --- ir/state.cpp | 2 +- tests/alive-tv/loops/issue951.srctgt.ll | 38 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/alive-tv/loops/issue951.srctgt.ll diff --git a/ir/state.cpp b/ir/state.cpp index 7fa02d75b..8d8e9d28a 100644 --- a/ir/state.cpp +++ b/ir/state.cpp @@ -1238,7 +1238,7 @@ expr State::sinkDomain() const { OrExpr ret; for (auto &[src, data] : I->second) { - ret.add(data.path()); + ret.add(data.path() && *data.UB()); } return ret(); } diff --git a/tests/alive-tv/loops/issue951.srctgt.ll b/tests/alive-tv/loops/issue951.srctgt.ll new file mode 100644 index 000000000..030b029cd --- /dev/null +++ b/tests/alive-tv/loops/issue951.srctgt.ll @@ -0,0 +1,38 @@ +; ERROR: Source is more defined than target +; TEST-ARGS: -src-unroll=3 -tgt-unroll=3 + +define i8 @src(i8 %v) { +entry: + %v.nonneg = icmp sgt i8 %v, -1 + br label %for.body + +for.body: + %sum = phi i8 [ 0, %entry ], [ %sum.next, %for.body ] + %sum.next = add i8 %sum, %v + %overflow = icmp ult i8 %sum.next, %sum + %cmp.i5.i = xor i1 %v.nonneg, %overflow + call void @use(i1 %cmp.i5.i) + br i1 %cmp.i5.i, label %for.body, label %cleanup1.loopexit + +cleanup1.loopexit: + %cmp.not.lcssa.ph = phi i8 [ %sum, %for.body ] + ret i8 %cmp.not.lcssa.ph +} + +define i8 @tgt(i8 %v) { +entry: + %v.nonneg = icmp sgt i8 %v, -1 + br label %for.body + +for.body: + %sum = phi i8 [ 0, %entry ], [ %sum.next, %for.body ] + %sum.next = add i8 %sum, %v + call void @use(i1 %v.nonneg) + br i1 %v.nonneg, label %for.body, label %cleanup1.loopexit + +cleanup1.loopexit: + %cmp.not.lcssa.ph = phi i8 [ %sum, %for.body ] + ret i8 %cmp.not.lcssa.ph +} + +declare void @use(i1)