1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
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`).
7 define i32 @assume_inevitable(i32* %a, i32* %b, i8* %c) {
8 ; CHECK-LABEL: @assume_inevitable(
10 ; CHECK-NEXT: [[M:%.*]] = alloca i64, align 8
11 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* [[A:%.*]], align 4
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 4
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)
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]]
29 %dummy = alloca i8, align 4
31 %0 = load i32, i32* %a, align 4
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
38 %dummy_eq = icmp ugt i32 %loadres, 42
39 tail call void @llvm.assume(i1 %dummy_eq)
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)
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)
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
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)
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"
65 declare i64 @llvm.objectsize.i64.p0i8(i8*, i1)
66 declare i32 @llvm.annotation.i32(i32, i8*, i8*, i32)
67 declare i8* @llvm.ptr.annotation.p0i8(i8*, i8*, i8*, i32)
69 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
70 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
72 declare {}* @llvm.invariant.start.p0i8(i64, i8* nocapture)
73 declare void @llvm.invariant.end.p0i8({}*, i64, i8* nocapture)
74 declare void @llvm.assume(i1)