From: Florian Hahn Date: Mon, 12 Jun 2023 16:07:01 +0000 (+0100) Subject: [ConstraintElim] Extend monotonic phi test coverage. X-Git-Tag: upstream/17.0.6~5395 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=06dab8f7438a7aae82157714c5b502680f78a382;p=platform%2Fupstream%2Fllvm.git [ConstraintElim] Extend monotonic phi test coverage. Add additional tests which exposed some crashes in upcoming patches and test for and-implied-by-operands handling. --- diff --git a/llvm/test/Transforms/ConstraintElimination/and-implied-by-operands.ll b/llvm/test/Transforms/ConstraintElimination/and-implied-by-operands.ll index 3b7674d..58b891f 100644 --- a/llvm/test/Transforms/ConstraintElimination/and-implied-by-operands.ll +++ b/llvm/test/Transforms/ConstraintElimination/and-implied-by-operands.ll @@ -263,3 +263,59 @@ exit: %res = phi i1 [ %c.1, %entry ], [ %sel, %then ] ret i1 %res } + +declare void @use(ptr) + +define void @test_monotonic_ptr_iv_inc_1_eq_to_uge(ptr %start, i16 %len) { +; CHECK-LABEL: @test_monotonic_ptr_iv_inc_1_eq_to_uge( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds i32, ptr [[START:%.*]], i16 [[LEN:%.*]] +; CHECK-NEXT: br label [[LOOP_PH:%.*]] +; CHECK: loop.ph: +; CHECK-NEXT: br label [[LOOP_HEADER:%.*]] +; CHECK: loop.header: +; CHECK-NEXT: [[PTR_IV:%.*]] = phi ptr [ [[START]], [[LOOP_PH]] ], [ [[PTR_IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ] +; CHECK-NEXT: [[LEN_NEG:%.*]] = icmp sgt i16 [[LEN]], 0 +; CHECK-NEXT: [[C:%.*]] = icmp ne ptr [[PTR_IV]], [[UPPER]] +; CHECK-NEXT: [[AND_0:%.*]] = and i1 [[LEN_NEG]], [[C]] +; CHECK-NEXT: br i1 [[AND_0]], label [[FOR_BODY:%.*]], label [[EXIT:%.*]] +; CHECK: for.body: +; CHECK-NEXT: [[T_1:%.*]] = icmp uge ptr [[PTR_IV]], [[START]] +; CHECK-NEXT: [[T_2:%.*]] = icmp ult ptr [[PTR_IV]], [[UPPER]] +; CHECK-NEXT: [[AND:%.*]] = and i1 [[T_1]], [[T_2]] +; CHECK-NEXT: br i1 [[AND]], label [[LOOP_LATCH]], label [[EXIT]] +; CHECK: loop.latch: +; CHECK-NEXT: call void @use(ptr [[PTR_IV]]) +; CHECK-NEXT: [[PTR_IV_NEXT]] = getelementptr inbounds i32, ptr [[PTR_IV]], i16 1 +; CHECK-NEXT: br label [[LOOP_HEADER]] +; CHECK: exit: +; CHECK-NEXT: ret void +; +entry: + %upper = getelementptr inbounds i32, ptr %start, i16 %len + br label %loop.ph + +loop.ph: + br label %loop.header + +loop.header: + %ptr.iv = phi ptr [ %start, %loop.ph ], [ %ptr.iv.next, %loop.latch ] + %len.neg = icmp sgt i16 %len, 0 + %c = icmp ne ptr %ptr.iv, %upper + %and.0 = and i1 %len.neg, %c + br i1 %and.0, label %for.body, label %exit + +for.body: + %t.1 = icmp uge ptr %ptr.iv, %start + %t.2 = icmp ult ptr %ptr.iv, %upper + %and = and i1 %t.1, %t.2 + br i1 %and, label %loop.latch, label %exit + +loop.latch: + call void @use(ptr %ptr.iv) + %ptr.iv.next = getelementptr inbounds i32, ptr %ptr.iv, i16 1 + br label %loop.header + +exit: + ret void +} diff --git a/llvm/test/Transforms/ConstraintElimination/monotonic-pointer-phis-crashes.ll b/llvm/test/Transforms/ConstraintElimination/monotonic-pointer-phis-crashes.ll new file mode 100644 index 0000000..37e0bac --- /dev/null +++ b/llvm/test/Transforms/ConstraintElimination/monotonic-pointer-phis-crashes.ll @@ -0,0 +1,100 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2 +; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s + +declare i1 @cond() +declare void @clobber() + + +define void @test_unreachable_latch(ptr %start, ptr %b) { +; CHECK-LABEL: define void @test_unreachable_latch +; CHECK-SAME: (ptr [[START:%.*]], ptr [[B:%.*]]) { +; CHECK-NEXT: entry: +; CHECK-NEXT: br label [[LOOP_HEADER:%.*]] +; CHECK: loop.header: +; CHECK-NEXT: [[NODE_1:%.*]] = phi ptr [ [[START]], [[ENTRY:%.*]] ], [ null, [[LOOP_LATCH:%.*]] ] +; CHECK-NEXT: [[C_0:%.*]] = icmp ne ptr [[NODE_1]], null +; CHECK-NEXT: br i1 [[C_0]], label [[THEN:%.*]], label [[EXIT:%.*]] +; CHECK: loop.latch: +; CHECK-NEXT: call void @clobber() +; CHECK-NEXT: br label [[LOOP_HEADER]] +; CHECK: if: +; CHECK-NEXT: [[C_2:%.*]] = icmp ne ptr [[B]], null +; CHECK-NEXT: [[AND:%.*]] = and i1 [[C_2]], [[C_0]] +; CHECK-NEXT: br i1 [[AND]], label [[THEN]], label [[EXIT]] +; CHECK: then: +; CHECK-NEXT: call void @clobber() +; CHECK-NEXT: br label [[EXIT]] +; CHECK: exit: +; CHECK-NEXT: ret void +; +entry: + br label %loop.header + +loop.header: + %node.1 = phi ptr [ %start, %entry ], [ null, %loop.latch ] + %c.0 = icmp ne ptr %node.1, null + br i1 %c.0, label %then, label %exit + +loop.latch: ; No predecessors! + call void @clobber() + br label %loop.header + +if: + %c.2 = icmp ne ptr %b, null + %and = and i1 %c.2, %c.0 + br i1 %and, label %then, label %exit + +then: + call void @clobber() + br label %exit + +exit: + ret void +} + +define void @test_cond_multi_use_with_one_use_simplified_before_adding_ne_fact(ptr %start, ptr %b) { +; CHECK-LABEL: define void @test_cond_multi_use_with_one_use_simplified_before_adding_ne_fact +; CHECK-SAME: (ptr [[START:%.*]], ptr [[B:%.*]]) { +; CHECK-NEXT: entry: +; CHECK-NEXT: br label [[LOOP_HEADER:%.*]] +; CHECK: loop.header: +; CHECK-NEXT: [[NODE_1:%.*]] = phi ptr [ [[START]], [[ENTRY:%.*]] ], [ null, [[LOOP_LATCH:%.*]] ] +; CHECK-NEXT: [[C_0:%.*]] = icmp ne ptr [[NODE_1]], null +; CHECK-NEXT: br i1 [[C_0]], label [[LOOP_LATCH]], label [[EXIT:%.*]] +; CHECK: loop.latch: +; CHECK-NEXT: [[C_1:%.*]] = call i1 @cond() +; CHECK-NEXT: br i1 [[C_1]], label [[IF:%.*]], label [[LOOP_HEADER]] +; CHECK: if: +; CHECK-NEXT: [[C_2:%.*]] = icmp ne ptr [[B]], null +; CHECK-NEXT: [[AND:%.*]] = and i1 [[C_2]], [[C_0]] +; CHECK-NEXT: br i1 [[AND]], label [[THEN:%.*]], label [[EXIT]] +; CHECK: then: +; CHECK-NEXT: call void @clobber() +; CHECK-NEXT: br label [[EXIT]] +; CHECK: exit: +; CHECK-NEXT: ret void +; +entry: + br label %loop.header + +loop.header: + %node.1 = phi ptr [ %start, %entry ], [ null, %loop.latch ] + %c.0 = icmp ne ptr %node.1, null + br i1 %c.0, label %loop.latch, label %exit + +loop.latch: + %c.1 = call i1 @cond() + br i1 %c.1, label %if, label %loop.header + +if: + %c.2 = icmp ne ptr %b, null + %and = and i1 %c.2, %c.0 + br i1 %and, label %then, label %exit + +then: + call void @clobber() + br label %exit + +exit: + ret void +}