|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4 |
| 2 | +; RUN: opt -S -passes=licm < %s | FileCheck %s |
| 3 | + |
| 4 | +; Adapted from |
| 5 | +; for(long i = 0; i < n; ++i) |
| 6 | +; a[i] = (i+1) * v; |
| 7 | +define void @test1(i64 %n) { |
| 8 | +; CHECK-LABEL: define void @test1( |
| 9 | +; CHECK-SAME: i64 [[N:%.*]]) { |
| 10 | +; CHECK-NEXT: entry: |
| 11 | +; CHECK-NEXT: br label [[FOR_PH:%.*]] |
| 12 | +; CHECK: for.ph: |
| 13 | +; CHECK-NEXT: [[VSCALE:%.*]] = tail call i64 @llvm.vscale.i64() |
| 14 | +; CHECK-NEXT: [[VSCALE_2:%.*]] = shl nuw nsw i64 [[VSCALE]], 1 |
| 15 | +; CHECK-NEXT: [[VSCALE_4:%.*]] = shl nuw nsw i64 [[VSCALE]], 2 |
| 16 | +; CHECK-NEXT: [[VEC_INIT:%.*]] = insertelement <vscale x 2 x i64> zeroinitializer, i64 1, i64 1 |
| 17 | +; CHECK-NEXT: [[DOTSPLATINSERT:%.*]] = insertelement <vscale x 2 x i64> poison, i64 [[VSCALE_2]], i64 0 |
| 18 | +; CHECK-NEXT: [[DOTSPLAT:%.*]] = shufflevector <vscale x 2 x i64> [[DOTSPLATINSERT]], <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer |
| 19 | +; CHECK-NEXT: br label [[FOR_BODY:%.*]] |
| 20 | +; CHECK: for.body: |
| 21 | +; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[FOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[FOR_BODY]] ] |
| 22 | +; CHECK-NEXT: [[VEC_IND:%.*]] = phi <vscale x 2 x i64> [ [[VEC_INIT]], [[FOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[FOR_BODY]] ] |
| 23 | +; CHECK-NEXT: [[STEP_ADD:%.*]] = add <vscale x 2 x i64> [[VEC_IND]], [[DOTSPLAT]] |
| 24 | +; CHECK-NEXT: [[ADD1:%.*]] = add nuw nsw <vscale x 2 x i64> [[VEC_IND]], shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> poison, i64 1, i64 0), <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer) |
| 25 | +; CHECK-NEXT: [[ADD2:%.*]] = add nuw nsw <vscale x 2 x i64> [[STEP_ADD]], shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> poison, i64 1, i64 0), <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer) |
| 26 | +; CHECK-NEXT: call void @use(<vscale x 2 x i64> [[ADD1]]) |
| 27 | +; CHECK-NEXT: call void @use(<vscale x 2 x i64> [[ADD2]]) |
| 28 | +; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[VSCALE_4]] |
| 29 | +; CHECK-NEXT: [[VEC_IND_NEXT]] = add <vscale x 2 x i64> [[STEP_ADD]], [[DOTSPLAT]] |
| 30 | +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N]] |
| 31 | +; CHECK-NEXT: br i1 [[CMP]], label [[FOR_END:%.*]], label [[FOR_BODY]] |
| 32 | +; CHECK: for.end: |
| 33 | +; CHECK-NEXT: ret void |
| 34 | +; |
| 35 | +entry: |
| 36 | + br label %for.ph |
| 37 | + |
| 38 | +for.ph: |
| 39 | + %vscale = tail call i64 @llvm.vscale.i64() |
| 40 | + %vscale.2 = shl nuw nsw i64 %vscale, 1 |
| 41 | + %vscale.4 = shl nuw nsw i64 %vscale, 2 |
| 42 | + %vec.init = insertelement <vscale x 2 x i64> zeroinitializer, i64 1, i64 1 |
| 43 | + %.splatinsert = insertelement <vscale x 2 x i64> poison, i64 %vscale.2, i64 0 |
| 44 | + %.splat = shufflevector <vscale x 2 x i64> %.splatinsert, <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer |
| 45 | + br label %for.body |
| 46 | + |
| 47 | +for.body: |
| 48 | + %index = phi i64 [ 0, %for.ph ], [ %index.next, %for.body ] |
| 49 | + %vec.ind = phi <vscale x 2 x i64> [ %vec.init, %for.ph ], [ %vec.ind.next, %for.body ] |
| 50 | + %step.add = add <vscale x 2 x i64> %vec.ind, %.splat |
| 51 | + %add1 = add nuw nsw <vscale x 2 x i64> %vec.ind, shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> poison, i64 1, i64 0), <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer) |
| 52 | + %add2 = add nuw nsw <vscale x 2 x i64> %step.add, shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> poison, i64 1, i64 0), <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer) |
| 53 | + call void @use(<vscale x 2 x i64> %add1) |
| 54 | + call void @use(<vscale x 2 x i64> %add2) |
| 55 | + %index.next = add nuw i64 %index, %vscale.4 |
| 56 | + %vec.ind.next = add <vscale x 2 x i64> %step.add, %.splat |
| 57 | + %cmp = icmp eq i64 %index.next, %n |
| 58 | + br i1 %cmp, label %for.end, label %for.body |
| 59 | + |
| 60 | +for.end: |
| 61 | + ret void |
| 62 | +} |
| 63 | + |
| 64 | +declare i64 @llvm.vscale.i64() |
| 65 | +declare void @use(<vscale x 2 x i64>) |
0 commit comments