1; RUN: opt -S -licm -o - %s | FileCheck %s 2; 3; Be sure that we don't hoist loads incorrectly if a loop has conditional UB. 4; See PR36228. 5 6declare void @check(i8) 7declare void @llvm.memcpy.p0i8.p0i8.i64(i8*, i8*, i64, i32, i1) 8 9; CHECK-LABEL: define void @buggy 10define void @buggy(i8* %src, i1* %kOne) { 11entry: 12 %dst = alloca [1 x i8], align 1 13 %0 = getelementptr inbounds [1 x i8], [1 x i8]* %dst, i64 0, i64 0 14 store i8 42, i8* %0, align 1 15 %src16 = bitcast i8* %src to i16* 16 %srcval = load i16, i16* %src16 17 br label %while.cond 18 19while.cond: ; preds = %if.end, %entry 20 %dp.0 = phi i8* [ %0, %entry ], [ %dp.1, %if.end ] 21 %1 = load volatile i1, i1* %kOne, align 4 22 br i1 %1, label %if.else, label %if.then 23 24if.then: ; preds = %while.cond 25 store i8 9, i8* %dp.0, align 1 26 br label %if.end 27 28if.else: ; preds = %while.cond 29 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dp.0, i8* %src, i64 2, i32 1, i1 false) 30 %dp.new = getelementptr inbounds i8, i8* %dp.0, i64 1 31 br label %if.end 32 33if.end: ; preds = %if.else, %if.then 34 %dp.1 = phi i8* [ %dp.0, %if.then ], [ %dp.new, %if.else ] 35 ; CHECK: %2 = load i8, i8* %0 36 %2 = load i8, i8* %0, align 1 37 ; CHECK-NEXT: call void @check(i8 %2) 38 call void @check(i8 %2) 39 br label %while.cond 40} 41