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(ptr %a) {
9 ; CHECK-NEXT: [[PTR:%.*]] = getelementptr inbounds i8, ptr [[A:%.*]], i64 4
10 ; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[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"(ptr [[PTR]], i64 4) ]
16 ; CHECK-NEXT: store i32 4, ptr [[PTR]], align 4
17 ; CHECK-NEXT: br label [[IF_END]]
19 ; CHECK-NEXT: ret void
22 %ptr = getelementptr inbounds i8, ptr %a, i64 4
23 %0 = ptrtoint ptr %ptr to i64
25 %2 = icmp eq i64 %1, 0
26 br i1 %2, label %if.then, label %if.end
28 if.then: ; preds = %entry
29 call void @llvm.assume(i1 true) [ "align"(ptr %ptr, i64 4) ]
30 %3 = ptrtoint ptr %ptr to i64
32 %5 = icmp eq i64 %4, 0
33 br i1 %5, label %if.then1, label %if.else1
35 if.then1: ; preds = %if.then
36 store i32 4, ptr %ptr, align 4
39 if.else1: ; preds = %if.then
40 store i8 1, ptr %ptr, align 1
43 if.end: ; preds = %if.then1, %if.else1, %entry
47 ; 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.
49 define void @f2(ptr %a) {
52 ; CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr [[A:%.*]], i64 32, i32 24) ]
53 ; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 8
54 ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[TMP0]] to i64
55 ; CHECK-NEXT: [[TMP2:%.*]] = and i64 [[TMP1]], 8
56 ; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i64 [[TMP2]], 0
57 ; CHECK-NEXT: br i1 [[TMP3]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
59 ; CHECK-NEXT: store i64 16, ptr [[TMP0]], align 4
60 ; CHECK-NEXT: br label [[IF_END:%.*]]
62 ; CHECK-NEXT: store i8 1, ptr [[TMP0]], align 1
63 ; CHECK-NEXT: br label [[IF_END]]
65 ; CHECK-NEXT: ret void
68 call void @llvm.assume(i1 true) [ "align"(ptr %a, i64 32, i32 24) ]
69 %0 = getelementptr inbounds i8, ptr %a, i64 8
70 %1 = ptrtoint ptr %0 to i64
72 %3 = icmp eq i64 %2, 0
73 br i1 %3, label %if.then, label %if.else
75 if.then: ; preds = %entry
76 store i64 16, ptr %0, align 4
79 if.else: ; preds = %entry
80 store i8 1, ptr %0, align 1
83 if.end: ; preds = %if.else, %if.then
87 define void @f3(i64 %a, ptr %b) {
89 ; CHECK-NEXT: [[C:%.*]] = ptrtoint ptr [[B:%.*]] to i64
90 ; CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr [[B]], i64 4294967296) ]
91 ; CHECK-NEXT: [[D:%.*]] = add i64 [[C]], [[A:%.*]]
92 ; CHECK-NEXT: call void @g(i64 [[D]])
93 ; CHECK-NEXT: ret void
95 %c = ptrtoint ptr %b to i64
96 call void @llvm.assume(i1 true) [ "align"(ptr %b, i64 4294967296) ]
104 define i8 @assume_align_zero(ptr %p) {
105 ; CHECK-LABEL: @assume_align_zero(
106 ; CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr [[P:%.*]], i64 0) ]
107 ; CHECK-NEXT: [[V:%.*]] = load i8, ptr [[P]], align 1
108 ; CHECK-NEXT: ret i8 [[V]]
110 call void @llvm.assume(i1 true) [ "align"(ptr %p, i64 0) ]
115 define i8 @assume_align_non_pow2(ptr %p) {
116 ; CHECK-LABEL: @assume_align_non_pow2(
117 ; CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr [[P:%.*]], i64 123) ]
118 ; CHECK-NEXT: [[V:%.*]] = load i8, ptr [[P]], align 1
119 ; CHECK-NEXT: ret i8 [[V]]
121 call void @llvm.assume(i1 true) [ "align"(ptr %p, i64 123) ]