140 lines · plain
1; REQUIRES: asserts2 3; RUN: opt -passes=loop-vectorize -debug-only=loop-vectorize \4; RUN: -prefer-predicate-over-epilogue=predicate-else-scalar-epilogue \5; RUN: -mtriple=riscv64 -mattr=+v -riscv-v-vector-bits-max=128 -disable-output < %s 2>&1 | FileCheck --check-prefixes=IF-EVL,CHECK %s6 7; RUN: opt -passes=loop-vectorize -debug-only=loop-vectorize \8; RUN: -prefer-predicate-over-epilogue=scalar-epilogue \9; RUN: -mtriple=riscv64 -mattr=+v -riscv-v-vector-bits-max=128 -disable-output < %s 2>&1 | FileCheck --check-prefixes=NO-VP,CHECK %s10 11define void @foo(ptr noalias %a, ptr noalias %b, ptr noalias %c, i64 %N) {12; IF-EVL: VPlan 'Initial VPlan for VF={1},UF>=1'13; IF-EVL-NOT: EXPLICIT-VECTOR-LENGTH-BASED-IV-PHI14;15; IF-EVL: VPlan 'Initial VPlan for VF={vscale x 1,vscale x 2,vscale x 4},UF={1}' {16; IF-EVL-NEXT: Live-in vp<[[VFUF:%[0-9]+]]> = VF * UF17; IF-EVL-NEXT: Live-in vp<[[VTC:%[0-9]+]]> = vector-trip-count18; IF-EVL-NEXT: Live-in ir<%N> = original trip-count19; IF-EVL-EMPTY:20; IF-EVL: vector.ph:21; IF-EVL-NEXT: Successor(s): vector loop22; IF-EVL-EMPTY:23; IF-EVL-NEXT: <x1> vector loop: {24; IF-EVL-NEXT: vector.body:25; IF-EVL-NEXT: EMIT vp<[[IV:%[0-9]+]]> = CANONICAL-INDUCTION26; IF-EVL-NEXT: EXPLICIT-VECTOR-LENGTH-BASED-IV-PHI vp<[[EVL_PHI:%[0-9]+]]> = phi ir<0>, vp<[[IV_NEXT:%.+]]>27; IF-EVL-NEXT: EMIT-SCALAR vp<[[AVL:%.+]]> = phi [ ir<%N>, vector.ph ], [ vp<[[AVL_NEXT:%.+]]>, vector.body ]28; IF-EVL-NEXT: EMIT-SCALAR vp<[[EVL:%.+]]> = EXPLICIT-VECTOR-LENGTH vp<[[AVL]]>29; IF-EVL-NEXT: vp<[[ST:%[0-9]+]]> = SCALAR-STEPS vp<[[EVL_PHI]]>, ir<1>, vp<[[EVL]]>30; IF-EVL-NEXT: CLONE ir<[[GEP1:%.+]]> = getelementptr inbounds ir<%b>, vp<[[ST]]>31; IF-EVL-NEXT: vp<[[PTR1:%[0-9]+]]> = vector-pointer inbounds ir<[[GEP1]]>32; IF-EVL-NEXT: WIDEN ir<[[LD1:%.+]]> = vp.load vp<[[PTR1]]>, vp<[[EVL]]>33; IF-EVL-NEXT: CLONE ir<[[GEP2:%.+]]> = getelementptr inbounds ir<%c>, vp<[[ST]]>34; IF-EVL-NEXT: vp<[[PTR2:%[0-9]+]]> = vector-pointer inbounds ir<[[GEP2]]>35; IF-EVL-NEXT: WIDEN ir<[[LD2:%.+]]> = vp.load vp<[[PTR2]]>, vp<[[EVL]]>36; IF-EVL-NEXT: WIDEN ir<[[ADD:%.+]]> = add nsw ir<[[LD2]]>, ir<[[LD1]]>37; IF-EVL-NEXT: CLONE ir<[[GEP3:%.+]]> = getelementptr inbounds ir<%a>, vp<[[ST]]>38; IF-EVL-NEXT: vp<[[PTR3:%[0-9]+]]> = vector-pointer inbounds ir<[[GEP3]]>39; IF-EVL-NEXT: WIDEN vp.store vp<[[PTR3]]>, ir<[[ADD]]>, vp<[[EVL]]>40; IF-EVL-NEXT: EMIT-SCALAR vp<[[CAST:%[0-9]+]]> = zext vp<[[EVL]]> to i6441; IF-EVL-NEXT: EMIT vp<[[IV_NEXT]]> = add vp<[[CAST]]>, vp<[[EVL_PHI]]>42; IF-EVL-NEXT: EMIT vp<[[AVL_NEXT]]> = sub nuw vp<[[AVL]]>, vp<[[CAST]]>43; IF-EVL-NEXT: EMIT vp<[[IV_NEXT_EXIT:%.+]]> = add vp<[[IV]]>, vp<[[VFUF]]>44; IF-EVL-NEXT: EMIT branch-on-count vp<[[IV_NEXT_EXIT]]>, vp<[[VTC]]>45; IF-EVL-NEXT: No successors46; IF-EVL-NEXT: }47 48; NO-VP: VPlan 'Initial VPlan for VF={vscale x 1,vscale x 2,vscale x 4},UF>=1' {49; NO-VP-NEXT: Live-in vp<[[VF:%[0-9]+]]> = VF50; NO-VP-NEXT: Live-in vp<[[VFUF:%[0-9]+]]> = VF * UF51; NO-VP-NEXT: Live-in vp<[[VTC:%[0-9]+]]> = vector-trip-count52; NO-VP-NEXT: Live-in ir<%N> = original trip-count53; NO-VP-EMPTY:54; NO-VP: vector.ph:55; NO-VP-NEXT: Successor(s): vector loop56; NO-VP-EMPTY:57; NO-VP-NEXT: <x1> vector loop: {58; NO-VP-NEXT: vector.body:59; NO-VP-NEXT: EMIT vp<[[IV:%[0-9]+]]> = CANONICAL-INDUCTION60; NO-VP-NEXT: vp<[[ST:%[0-9]+]]> = SCALAR-STEPS vp<[[IV]]>, ir<1>, vp<[[VF]]>61; NO-VP-NEXT: CLONE ir<[[GEP1:%.+]]> = getelementptr inbounds ir<%b>, vp<[[ST]]>62; NO-VP-NEXT: vp<[[PTR1:%[0-9]+]]> = vector-pointer inbounds ir<[[GEP1]]>63; NO-VP-NEXT: WIDEN ir<[[LD1:%.+]]> = load vp<[[PTR1]]>64; NO-VP-NEXT: CLONE ir<[[GEP2:%.+]]> = getelementptr inbounds ir<%c>, vp<[[ST]]>65; NO-VP-NEXT: vp<[[PTR2:%[0-9]+]]> = vector-pointer inbounds ir<[[GEP2]]>66; NO-VP-NEXT: WIDEN ir<[[LD2:%.+]]> = load vp<[[PTR2]]>67; NO-VP-NEXT: WIDEN ir<[[ADD:%.+]]> = add nsw ir<[[LD2]]>, ir<[[LD1]]>68; NO-VP-NEXT: CLONE ir<[[GEP3:%.+]]> = getelementptr inbounds ir<%a>, vp<[[ST]]>69; NO-VP-NEXT: vp<[[PTR3:%[0-9]+]]> = vector-pointer inbounds ir<[[GEP3]]>70; NO-VP-NEXT: WIDEN store vp<[[PTR3]]>, ir<[[ADD]]>71; NO-VP-NEXT: EMIT vp<[[IV_NEXT:%.+]]> = add nuw vp<[[IV]]>, vp<[[VFUF]]>72; NO-VP-NEXT: EMIT branch-on-count vp<[[IV_NEXT]]>, vp<[[VTC]]>73; NO-VP-NEXT: No successors74; NO-VP-NEXT: }75 76entry:77 br label %for.body78 79for.body:80 %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]81 %arrayidx = getelementptr inbounds i32, ptr %b, i64 %iv82 %0 = load i32, ptr %arrayidx, align 483 %arrayidx2 = getelementptr inbounds i32, ptr %c, i64 %iv84 %1 = load i32, ptr %arrayidx2, align 485 %add = add nsw i32 %1, %086 %arrayidx4 = getelementptr inbounds i32, ptr %a, i64 %iv87 store i32 %add, ptr %arrayidx4, align 488 %iv.next = add nuw nsw i64 %iv, 189 %exitcond.not = icmp eq i64 %iv.next, %N90 br i1 %exitcond.not, label %for.cond.cleanup, label %for.body91 92for.cond.cleanup:93 ret void94}95 96define void @safe_dep(ptr %p) {97; CHECK: VPlan 'Initial VPlan for VF={vscale x 1,vscale x 2},UF>=1' {98; CHECK-NEXT: Live-in vp<[[VF:%[0-9]+]]> = VF99; CHECK-NEXT: Live-in vp<[[VFUF:%[0-9]+]]> = VF * UF100; CHECK-NEXT: Live-in vp<[[VTC:%[0-9]+]]> = vector-trip-count101; CHECK-NEXT: Live-in ir<512> = original trip-count102; CHECK-EMPTY:103; CHECK: vector.ph:104; CHECK-NEXT: Successor(s): vector loop105; CHECK-EMPTY:106; CHECK-NEXT: <x1> vector loop: {107; CHECK-NEXT: vector.body:108; CHECK-NEXT: EMIT vp<[[IV:%[0-9]+]]> = CANONICAL-INDUCTION109; CHECK-NEXT: vp<[[ST:%[0-9]+]]> = SCALAR-STEPS vp<[[IV]]>, ir<1>, vp<[[VF]]>110; CHECK-NEXT: CLONE ir<[[GEP1:%.+]]> = getelementptr ir<%p>, vp<[[ST]]>111; CHECK-NEXT: vp<[[PTR1:%[0-9]+]]> = vector-pointer ir<[[GEP1]]>112; CHECK-NEXT: WIDEN ir<[[V:%.+]]> = load vp<[[PTR1]]>113; CHECK-NEXT: CLONE ir<[[OFFSET:.+]]> = add vp<[[ST]]>, ir<100>114; CHECK-NEXT: CLONE ir<[[GEP2:%.+]]> = getelementptr ir<%p>, ir<[[OFFSET]]>115; CHECK-NEXT: vp<[[PTR2:%[0-9]+]]> = vector-pointer ir<[[GEP2]]>116; CHECK-NEXT: WIDEN store vp<[[PTR2]]>, ir<[[V]]>117; CHECK-NEXT: EMIT vp<[[IV_NEXT:%.+]]> = add nuw vp<[[IV]]>, vp<[[VFUF]]>118; CHECK-NEXT: EMIT branch-on-count vp<[[IV_NEXT]]>, vp<[[VTC]]>119; CHECK-NEXT: No successors120; CHECK-NEXT: }121 122entry:123 br label %loop124 125loop:126 %iv = phi i64 [0, %entry], [%iv.next, %loop]127 %a1 = getelementptr i64, ptr %p, i64 %iv128 %v = load i64, ptr %a1, align 32129 %offset = add i64 %iv, 100130 %a2 = getelementptr i64, ptr %p, i64 %offset131 store i64 %v, ptr %a2, align 32132 %iv.next = add i64 %iv, 1133 %cmp = icmp ne i64 %iv, 511134 br i1 %cmp, label %loop, label %exit135 136exit:137 ret void138}139 140