1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=instcombine,simplifycfg < %s 2>&1 | FileCheck %s
4 declare void @llvm.assume(i1 noundef)
6 define void @f1(i8* %a) {
9 ; CHECK-NEXT: [[PTR:%.*]] = getelementptr inbounds i8, i8* [[A:%.*]], i64 4
10 ; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint i8* [[PTR]] to i64
11 ; CHECK-NEXT: [[TMP1:%.*]] = and i64 [[TMP0]], 3
12 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], 0
13 ; CHECK-NEXT: br i1 [[TMP2]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
15 ; CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* [[PTR]], i64 4) ]
16 ; CHECK-NEXT: [[TMP3:%.*]] = bitcast i8* [[PTR]] to i32*
17 ; CHECK-NEXT: store i32 4, i32* [[TMP3]], align 4
18 ; CHECK-NEXT: br label [[IF_END]]
20 ; CHECK-NEXT: ret void
23 %ptr = getelementptr inbounds i8, i8* %a, i64 4
24 %0 = ptrtoint i8* %ptr to i64
26 %2 = icmp eq i64 %1, 0
27 br i1 %2, label %if.then, label %if.end
29 if.then: ; preds = %entry
30 call void @llvm.assume(i1 true) [ "align"(i8* %ptr, i64 4) ]
31 %3 = ptrtoint i8* %ptr to i64
33 %5 = icmp eq i64 %4, 0
34 br i1 %5, label %if.then1, label %if.else1
36 if.then1: ; preds = %if.then
37 %6 = bitcast i8* %ptr to i32*
38 store i32 4, i32* %6, align 4
41 if.else1: ; preds = %if.then
42 store i8 1, i8* %ptr, align 1
45 if.end: ; preds = %if.then1, %if.else1, %entry
49 ; TODO: We could fold away the branch "br i1 %3, ..." by either using a GEP or make getKnowledgeValidInContext aware the alignment bundle offset, and the improvement of value tracking of GEP.
51 define void @f2(i8* %a) {
54 ; CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* [[A:%.*]], i64 32, i32 24) ]
55 ; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds i8, i8* [[A]], i64 8
56 ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint i8* [[TMP0]] to i64
57 ; CHECK-NEXT: [[TMP2:%.*]] = and i64 [[TMP1]], 8
58 ; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i64 [[TMP2]], 0
59 ; CHECK-NEXT: br i1 [[TMP3]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
61 ; CHECK-NEXT: [[TMP4:%.*]] = bitcast i8* [[TMP0]] to i64*
62 ; CHECK-NEXT: store i64 16, i64* [[TMP4]], align 8
63 ; CHECK-NEXT: br label [[IF_END:%.*]]
65 ; CHECK-NEXT: store i8 1, i8* [[TMP0]], align 8
66 ; CHECK-NEXT: br label [[IF_END]]
68 ; CHECK-NEXT: ret void
71 call void @llvm.assume(i1 true) [ "align"(i8* %a, i64 32, i32 24) ]
72 %0 = getelementptr inbounds i8, i8* %a, i64 8
73 %1 = ptrtoint i8* %0 to i64
75 %3 = icmp eq i64 %2, 0
76 br i1 %3, label %if.then, label %if.else
78 if.then: ; preds = %entry
79 %4 = bitcast i8* %0 to i64*
80 store i64 16, i64* %4, align 4
83 if.else: ; preds = %entry
84 store i8 1, i8* %0, align 1
87 if.end: ; preds = %if.else, %if.then