xref: /llvm-project/llvm/test/Transforms/LoopIdiom/memcpy-inline-intrinsic.ll (revision 055fb7795aa219a3d274d280ec9129784f169f56)
137b6e03cSJon Roelofs; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
248c6b272SRoman Lebedev; RUN: opt -passes=loop-idiom < %s -S | FileCheck %s
337b6e03cSJon Roelofs
437b6e03cSJon Roelofs%struct.S = type { i32, i32, i8 }
537b6e03cSJon Roelofs
637b6e03cSJon Roelofs; unsigned copy_noalias(S* __restrict a, S *b, int n) {
737b6e03cSJon Roelofs;   for (int i = 0; i < n; i++) {
837b6e03cSJon Roelofs;     a[i] = b[i];
937b6e03cSJon Roelofs;   }
1037b6e03cSJon Roelofs;   return sizeof(a[0]);
1137b6e03cSJon Roelofs; }
1237b6e03cSJon Roelofs
1337b6e03cSJon Roelofs; Function Attrs: nofree nounwind uwtable mustprogress
14*055fb779SNikita Popovdefine dso_local i32 @copy_noalias(ptr noalias nocapture %a, ptr nocapture readonly %b, i32 %n) local_unnamed_addr #0 {
1537b6e03cSJon Roelofs; CHECK-LABEL: @copy_noalias(
1637b6e03cSJon Roelofs; CHECK-NEXT:  entry:
1737b6e03cSJon Roelofs; CHECK-NEXT:    [[CMP7:%.*]] = icmp sgt i32 [[N:%.*]], 0
1837b6e03cSJon Roelofs; CHECK-NEXT:    br i1 [[CMP7]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
1937b6e03cSJon Roelofs; CHECK:       for.body.preheader:
2037b6e03cSJon Roelofs; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
2137b6e03cSJon Roelofs; CHECK:       for.cond.cleanup.loopexit:
2237b6e03cSJon Roelofs; CHECK-NEXT:    br label [[FOR_COND_CLEANUP]]
2337b6e03cSJon Roelofs; CHECK:       for.cond.cleanup:
2437b6e03cSJon Roelofs; CHECK-NEXT:    ret i32 12
2537b6e03cSJon Roelofs; CHECK:       for.body:
2637b6e03cSJon Roelofs; CHECK-NEXT:    [[I_08:%.*]] = phi i32 [ [[INC:%.*]], [[FOR_BODY]] ], [ 0, [[FOR_BODY_PREHEADER]] ]
2737b6e03cSJon Roelofs; CHECK-NEXT:    [[IDXPROM:%.*]] = zext i32 [[I_08]] to i64
28*055fb779SNikita Popov; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds [[STRUCT_S:%.*]], ptr [[B:%.*]], i64 [[IDXPROM]]
29*055fb779SNikita Popov; CHECK-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds [[STRUCT_S]], ptr [[A:%.*]], i64 [[IDXPROM]]
30*055fb779SNikita Popov; CHECK-NEXT:    call void @llvm.memcpy.inline.p0.p0.i64(ptr nonnull align 4 dereferenceable(12) [[ARRAYIDX2]], ptr nonnull align 4 dereferenceable(12) [[ARRAYIDX]], i64 12, i1 false)
3137b6e03cSJon Roelofs; CHECK-NEXT:    [[INC]] = add nuw nsw i32 [[I_08]], 1
3237b6e03cSJon Roelofs; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[INC]], [[N]]
3337b6e03cSJon Roelofs; CHECK-NEXT:    br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]]
3437b6e03cSJon Roelofs;
3537b6e03cSJon Roelofsentry:
3637b6e03cSJon Roelofs  %cmp7 = icmp sgt i32 %n, 0
3737b6e03cSJon Roelofs  br i1 %cmp7, label %for.body.preheader, label %for.cond.cleanup
3837b6e03cSJon Roelofs
3937b6e03cSJon Roelofsfor.body.preheader:                               ; preds = %entry
4037b6e03cSJon Roelofs  br label %for.body
4137b6e03cSJon Roelofs
4237b6e03cSJon Roelofsfor.cond.cleanup.loopexit:                        ; preds = %for.body
4337b6e03cSJon Roelofs  br label %for.cond.cleanup
4437b6e03cSJon Roelofs
4537b6e03cSJon Roelofsfor.cond.cleanup:                                 ; preds = %for.cond.cleanup.loopexit, %entry
4637b6e03cSJon Roelofs  ret i32 12
4737b6e03cSJon Roelofs
4837b6e03cSJon Roelofsfor.body:                                         ; preds = %for.body.preheader, %for.body
4937b6e03cSJon Roelofs  %i.08 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]
5037b6e03cSJon Roelofs  %idxprom = zext i32 %i.08 to i64
51*055fb779SNikita Popov  %arrayidx = getelementptr inbounds %struct.S, ptr %b, i64 %idxprom
52*055fb779SNikita Popov  %arrayidx2 = getelementptr inbounds %struct.S, ptr %a, i64 %idxprom
53*055fb779SNikita Popov  call void @llvm.memcpy.inline.p0.p0.i64(ptr nonnull align 4 dereferenceable(12) %arrayidx2, ptr nonnull align 4 dereferenceable(12) %arrayidx, i64 12, i1 false)
5437b6e03cSJon Roelofs  %inc = add nuw nsw i32 %i.08, 1
5537b6e03cSJon Roelofs  %cmp = icmp slt i32 %inc, %n
5637b6e03cSJon Roelofs  br i1 %cmp, label %for.body, label %for.cond.cleanup.loopexit
5737b6e03cSJon Roelofs}
5837b6e03cSJon Roelofs
5937b6e03cSJon Roelofs; Function Attrs: argmemonly nofree nosync nounwind willreturn
60*055fb779SNikita Popovdeclare void @llvm.memcpy.inline.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1
61