148c6b272SRoman Lebedev; RUN: opt -passes=loop-idiom -S < %s | FileCheck %s 2cee313d2SEric Christopher 3cee313d2SEric Christophertarget datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 4cee313d2SEric Christophertarget triple = "x86_64-unknown-linux-gnu" 5cee313d2SEric Christopher 6cee313d2SEric Christopherdefine void @test1() { 7cee313d2SEric Christopherentry: 8cee313d2SEric Christopher br label %for.body.preheader 9cee313d2SEric Christopher 10cee313d2SEric Christopherfor.body.preheader: ; preds = %for.cond 11cee313d2SEric Christopher br label %for.body 12cee313d2SEric Christopher 13cee313d2SEric Christopherfor.body: ; preds = %for.body, %for.body.preheader 14cee313d2SEric Christopher %indvars.iv = phi i32 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ] 15*055fb779SNikita Popov %add.ptr3 = getelementptr inbounds i32, ptr null, i32 %indvars.iv 16*055fb779SNikita Popov %add.ptr4 = getelementptr inbounds i32, ptr %add.ptr3, i32 1 17*055fb779SNikita Popov %0 = load i32, ptr %add.ptr4, align 4 18*055fb779SNikita Popov store i32 %0, ptr %add.ptr3, align 4 19cee313d2SEric Christopher %indvars.iv.next = add nsw i32 %indvars.iv, 1 20cee313d2SEric Christopher %exitcond = icmp ne i32 %indvars.iv.next, 6 21cee313d2SEric Christopher br i1 %exitcond, label %for.body, label %for.body.preheader 22cee313d2SEric Christopher} 23cee313d2SEric Christopher 24cee313d2SEric Christopher; CHECK-LABEL: define void @test1( 25*055fb779SNikita Popov; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 null, ptr align 4 inttoptr (i64 4 to ptr), i64 24, i1 false) 26cee313d2SEric Christopher; CHECK-NOT: store 27cee313d2SEric Christopher 28cee313d2SEric Christopherdefine void @test1_no_null_opt() #0 { 29cee313d2SEric Christopherentry: 30cee313d2SEric Christopher br label %for.body.preheader 31cee313d2SEric Christopher 32cee313d2SEric Christopherfor.body.preheader: ; preds = %for.cond 33cee313d2SEric Christopher br label %for.body 34cee313d2SEric Christopher 35cee313d2SEric Christopherfor.body: ; preds = %for.body, %for.body.preheader 36cee313d2SEric Christopher %indvars.iv = phi i32 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ] 37*055fb779SNikita Popov %add.ptr3 = getelementptr inbounds i32, ptr null, i32 %indvars.iv 38*055fb779SNikita Popov %add.ptr4 = getelementptr inbounds i32, ptr %add.ptr3, i32 1 39*055fb779SNikita Popov %0 = load i32, ptr %add.ptr4, align 4 40*055fb779SNikita Popov store i32 %0, ptr %add.ptr3, align 4 41cee313d2SEric Christopher %indvars.iv.next = add nsw i32 %indvars.iv, 1 42cee313d2SEric Christopher %exitcond = icmp ne i32 %indvars.iv.next, 6 43cee313d2SEric Christopher br i1 %exitcond, label %for.body, label %for.body.preheader 44cee313d2SEric Christopher} 45cee313d2SEric Christopher 46cee313d2SEric Christopher; CHECK-LABEL: define void @test1_no_null_opt( 47cee313d2SEric Christopher; CHECK-NOT: call void @llvm.memcpy 48cee313d2SEric Christopher; CHECK: getelementptr 49cee313d2SEric Christopher; CHECK: getelementptr 50cee313d2SEric Christopher; CHECK: load 51cee313d2SEric Christopher; CHECK: store 52cee313d2SEric Christopher 53f89f7da9SNikita Popovattributes #0 = { null_pointer_is_valid } 54