1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -instcombine -S | FileCheck %s 3 4; Check that assume is propagated backwards through all 5; operations that are `isGuaranteedToTransferExecutionToSuccessor` 6; (it should reach the load and mark it as `align 32`). 7define i32 @assume_inevitable(i32* %a, i32* %b, i8* %c) { 8; CHECK-LABEL: @assume_inevitable( 9; CHECK-NEXT: entry: 10; CHECK-NEXT: [[M:%.*]] = alloca i64, align 8 11; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* [[A:%.*]], align 32 12; CHECK-NEXT: [[LOADRES:%.*]] = load i32, i32* [[B:%.*]], align 4 13; CHECK-NEXT: [[LOADRES2:%.*]] = call i32 @llvm.annotation.i32(i32 [[LOADRES]], i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str1, i64 0, i64 0), i32 2) 14; CHECK-NEXT: store i32 [[LOADRES2]], i32* [[A]], align 32 15; CHECK-NEXT: [[DUMMY_EQ:%.*]] = icmp ugt i32 [[LOADRES]], 42 16; CHECK-NEXT: tail call void @llvm.assume(i1 [[DUMMY_EQ]]) 17; CHECK-NEXT: [[M_I8:%.*]] = bitcast i64* [[M]] to i8* 18; CHECK-NEXT: [[M_A:%.*]] = call i8* @llvm.ptr.annotation.p0i8(i8* nonnull [[M_I8]], i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str1, i64 0, i64 0), i32 2, i8* null) 19; CHECK-NEXT: [[M_X:%.*]] = bitcast i8* [[M_A]] to i64* 20; CHECK-NEXT: [[OBJSZ:%.*]] = call i64 @llvm.objectsize.i64.p0i8(i8* [[C:%.*]], i1 false, i1 false, i1 false) 21; CHECK-NEXT: store i64 [[OBJSZ]], i64* [[M_X]], align 4 22; CHECK-NEXT: [[PTRINT:%.*]] = ptrtoint i32* [[A]] to i64 23; CHECK-NEXT: [[MASKEDPTR:%.*]] = and i64 [[PTRINT]], 31 24; CHECK-NEXT: [[MASKCOND:%.*]] = icmp eq i64 [[MASKEDPTR]], 0 25; CHECK-NEXT: tail call void @llvm.assume(i1 [[MASKCOND]]) 26; CHECK-NEXT: ret i32 [[TMP0]] 27; 28entry: 29 %dummy = alloca i8, align 4 30 %m = alloca i64 31 %0 = load i32, i32* %a, align 4 32 33 ; START perform a bunch of inevitable operations 34 %loadres = load i32, i32* %b 35 %loadres2 = call i32 @llvm.annotation.i32(i32 %loadres, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str1, i32 0, i32 0), i32 2) 36 store i32 %loadres2, i32* %a 37 38 %dummy_eq = icmp ugt i32 %loadres, 42 39 tail call void @llvm.assume(i1 %dummy_eq) 40 41 call void @llvm.lifetime.start.p0i8(i64 1, i8* %dummy) 42 %i = call {}* @llvm.invariant.start.p0i8(i64 1, i8* %dummy) 43 call void @llvm.invariant.end.p0i8({}* %i, i64 1, i8* %dummy) 44 call void @llvm.lifetime.end.p0i8(i64 1, i8* %dummy) 45 46 %m_i8 = bitcast i64* %m to i8* 47 %m_a = call i8* @llvm.ptr.annotation.p0i8(i8* %m_i8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str1, i32 0, i32 0), i32 2, i8* null) 48 %m_x = bitcast i8* %m_a to i64* 49 %objsz = call i64 @llvm.objectsize.i64.p0i8(i8* %c, i1 false) 50 store i64 %objsz, i64* %m_x 51 ; END perform a bunch of inevitable operations 52 53 ; AND here's the assume: 54 %ptrint = ptrtoint i32* %a to i64 55 %maskedptr = and i64 %ptrint, 31 56 %maskcond = icmp eq i64 %maskedptr, 0 57 tail call void @llvm.assume(i1 %maskcond) 58 59 ret i32 %0 60} 61 62@.str = private unnamed_addr constant [4 x i8] c"sth\00", section "llvm.metadata" 63@.str1 = private unnamed_addr constant [4 x i8] c"t.c\00", section "llvm.metadata" 64 65declare i64 @llvm.objectsize.i64.p0i8(i8*, i1) 66declare i32 @llvm.annotation.i32(i32, i8*, i8*, i32) 67declare i8* @llvm.ptr.annotation.p0i8(i8*, i8*, i8*, i32, i8*) 68 69declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) 70declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) 71 72declare {}* @llvm.invariant.start.p0i8(i64, i8* nocapture) 73declare void @llvm.invariant.end.p0i8({}*, i64, i8* nocapture) 74declare void @llvm.assume(i1) 75