diff --git a/llvm/test/Analysis/CostModel/RISCV/const-loop.ll b/llvm/test/Analysis/CostModel/RISCV/const-loop.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Analysis/CostModel/RISCV/const-loop.ll @@ -0,0 +1,143 @@ +; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 2 +; RUN: opt -passes="print" 2>&1 -disable-output -mtriple=riscv64 -mattr=+v,+f,+d,+zfh,+experimental-zvfh -riscv-v-vector-bits-min=128 -riscv-v-fixed-length-vector-lmul-max=1 < %s | FileCheck %s +; Check that we don't crash querying costs when vectors are not enabled. +; RUN: opt -passes="print" 2>&1 -disable-output -mtriple=riscv64 + +; FIXME: These tests include instructions that account for the cost of constant +; materialisation in their own cost. However in practice, because they are in a +; loop, these constants are hoisted out by LICM, and should probably be ignored. + +define void @add_v4i32(ptr %p) { +; CHECK-LABEL: 'add_v4i32' +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: br label %loop +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %i = phi i32 [ 0, %entry ], [ %i.next, %loop ] +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %q = getelementptr <4 x i32>, ptr %p, i32 %i +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %x = load <4 x i32>, ptr %q, align 16 +; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %y = add <4 x i32> %x, +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store <4 x i32> %y, ptr %q, align 16 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %i.next = add i32 %i, 1 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %done = icmp eq i32 %i, 1024 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: br i1 %done, label %exit, label %loop +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; +entry: + br label %loop +loop: + %i = phi i32 [0, %entry], [%i.next, %loop] + %q = getelementptr <4 x i32>, ptr %p, i32 %i + %x = load <4 x i32>, ptr %q + %y = add <4 x i32> %x, + store <4 x i32> %y, ptr %q + %i.next = add i32 %i, 1 + %done = icmp eq i32 %i, 1024 + br i1 %done, label %exit, label %loop +exit: + ret void +} + +define void @store_v4i32(ptr %p) { +; CHECK-LABEL: 'store_v4i32' +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: br label %loop +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %i = phi i32 [ 0, %entry ], [ %i.next, %loop ] +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %q = getelementptr <4 x i32>, ptr %p, i32 %i +; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: store <4 x i32> , ptr %q, align 16 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %i.next = add i32 %i, 1 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %done = icmp eq i32 %i, 1024 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: br i1 %done, label %exit, label %loop +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; +entry: + br label %loop +loop: + %i = phi i32 [0, %entry], [%i.next, %loop] + %q = getelementptr <4 x i32>, ptr %p, i32 %i + store <4 x i32> , ptr %q + %i.next = add i32 %i, 1 + %done = icmp eq i32 %i, 1024 + br i1 %done, label %exit, label %loop +exit: + ret void +} + +define void @phi_v2i64(ptr noalias %p, ptr noalias %q) { +; CHECK-LABEL: 'phi_v2i64' +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: br label %loop +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %i = phi i32 [ 0, %entry ], [ %i.next, %loop.2 ] +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %p.i = getelementptr i32, ptr %p, i32 %i +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %l = load i32, ptr %p.i, align 4 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %cond = icmp eq i32 %l, 0 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: br i1 %cond, label %left, label %right +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: br label %loop.2 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: br label %loop.2 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %x = phi <2 x i64> [ , %left ], [ , %right ] +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %q.vec = getelementptr <2 x i64>, ptr %q, i32 %i +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store <2 x i64> %x, ptr %q.vec, align 16 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %i.next = add i32 %i, 1 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %done = icmp eq i32 %i, 1024 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: br i1 %done, label %end, label %loop +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; +entry: + br label %loop +loop: + %i = phi i32 [0, %entry], [%i.next, %loop.2] + %p.i = getelementptr i32, ptr %p, i32 %i + %l = load i32, ptr %p.i + %cond = icmp eq i32 %l, 0 + br i1 %cond, label %left, label %right +left: + br label %loop.2 +right: + br label %loop.2 +loop.2: + %x = phi <2 x i64> [, %left], [, %right] + %q.vec = getelementptr <2 x i64>, ptr %q, i32 %i + store <2 x i64> %x, ptr %q.vec + %i.next = add i32 %i, 1 + %done = icmp eq i32 %i, 1024 + br i1 %done, label %end, label %loop +end: + ret void +} + + +define void @phi_i32(ptr noalias %p, ptr noalias %q) { +; CHECK-LABEL: 'phi_i32' +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: br label %loop +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %i = phi i32 [ 0, %entry ], [ %i.next, %loop.2 ] +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %p.i = getelementptr i32, ptr %p, i32 %i +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %l = load i32, ptr %p.i, align 4 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %cond = icmp eq i32 %l, 0 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: br i1 %cond, label %left, label %right +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: br label %loop.2 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: br label %loop.2 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %x = phi i32 [ 12341234, %left ], [ 84838383, %right ] +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %q.vec = getelementptr i32, ptr %q, i32 %i +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store i32 %x, ptr %q.vec, align 4 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %i.next = add i32 %i, 1 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %done = icmp eq i32 %i, 1024 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: br i1 %done, label %end, label %loop +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; +entry: + br label %loop +loop: + %i = phi i32 [0, %entry], [%i.next, %loop.2] + %p.i = getelementptr i32, ptr %p, i32 %i + %l = load i32, ptr %p.i + %cond = icmp eq i32 %l, 0 + br i1 %cond, label %left, label %right +left: + br label %loop.2 +right: + br label %loop.2 +loop.2: + %x = phi i32 [12341234, %left], [84838383, %right] + %q.vec = getelementptr i32, ptr %q, i32 %i + store i32 %x, ptr %q.vec + %i.next = add i32 %i, 1 + %done = icmp eq i32 %i, 1024 + br i1 %done, label %end, label %loop +end: + ret void +}