diff --git a/llvm/test/Transforms/Reassociate/reassociate-not-from-the-outside-of-the-loop.ll b/llvm/test/Transforms/Reassociate/reassociate-not-from-the-outside-of-the-loop.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/Reassociate/reassociate-not-from-the-outside-of-the-loop.ll @@ -0,0 +1,44 @@ +; RUN: opt -passes=reassociate -S < %s | FileCheck %s + +; This test is to ensure that no computations are pulled into a loop +; by the Reassociate pass. Doing so can result in the loop invariants not being +; computed before the loop anymore. In case of this test, it would add an extra +; multiplication into the loop. + +; FIXME: the checks below need to be inverted to confirm the change to the +; Reassociate pass. + +define void @innermost_loop(i32 %i, double %d1, double %d2, double %delta, ptr %cells) { +; CHECK-LABEL: @innermost_loop( +entry: +; CHECK-LABEL: entry: + %mul = fmul fast double %d1, %delta + %mul1 = fmul fast double %d2, %delta +; CHECK-NOT: %{{.*}} = fmul {{.*}} %delta + br label %for.cond + +for.cond: + %j.0 = phi i32 [ 0, %entry ], [ %add, %for.body ] + %cmp.not = icmp sgt i32 %j.0, %i + br i1 %cmp.not, label %for.end, label %for.body + +for.body: +; CHECK-LABEL: for.body: + %add = add nuw nsw i32 %j.0, 1 + %idxprom = zext i32 %add to i64 + %arrayidx = getelementptr inbounds double, ptr %cells, i64 %idxprom + %0 = load double, ptr %arrayidx + %mul2 = fmul fast double %mul, %0 + %idxprom3 = zext i32 %j.0 to i64 + %arrayidx4 = getelementptr inbounds double, ptr %cells, i64 %idxprom3 + %1 = load double, ptr %arrayidx4 + %mul5 = fmul fast double %mul1, %1 + %add6 = fadd fast double %mul2, %mul5 +; CHECK: %reass{{.*}} = fadd +; CHECK-NEXT: %reass{{.*}} = fmul {{.*}} %delta + store double %add6, ptr %arrayidx4 + br label %for.cond + +for.end: + ret void +}