1 ; RUN: opt -instcombine -S %s | FileCheck %s
2 target datalayout = "p:32:32"
5 define i1 @alloca_argument_compare(i64* %arg) {
7 %cmp = icmp eq i64* %arg, %alloc
9 ; CHECK-LABEL: alloca_argument_compare
13 define i1 @alloca_argument_compare_swapped(i64* %arg) {
15 %cmp = icmp eq i64* %alloc, %arg
17 ; CHECK-LABEL: alloca_argument_compare_swapped
21 define i1 @alloca_argument_compare_ne(i64* %arg) {
23 %cmp = icmp ne i64* %arg, %alloc
25 ; CHECK-LABEL: alloca_argument_compare_ne
29 define i1 @alloca_argument_compare_derived_ptrs(i64* %arg, i64 %x) {
30 %alloc = alloca i64, i64 8
31 %p = getelementptr i64, i64* %arg, i64 %x
32 %q = getelementptr i64, i64* %alloc, i64 3
33 %cmp = icmp eq i64* %p, %q
35 ; CHECK-LABEL: alloca_argument_compare_derived_ptrs
39 declare void @escape(i64*)
40 define i1 @alloca_argument_compare_escaped_alloca(i64* %arg) {
42 call void @escape(i64* %alloc)
43 %cmp = icmp eq i64* %alloc, %arg
45 ; CHECK-LABEL: alloca_argument_compare_escaped_alloca
46 ; CHECK: %cmp = icmp eq i64* %alloc, %arg
50 declare void @check_compares(i1, i1)
51 define void @alloca_argument_compare_two_compares(i64* %p) {
52 %q = alloca i64, i64 8
53 %r = getelementptr i64, i64* %p, i64 1
54 %s = getelementptr i64, i64* %q, i64 2
55 %cmp1 = icmp eq i64* %p, %q
56 %cmp2 = icmp eq i64* %r, %s
57 call void @check_compares(i1 %cmp1, i1 %cmp2)
59 ; We will only fold if there is a single cmp.
60 ; CHECK-LABEL: alloca_argument_compare_two_compares
61 ; CHECK: call void @check_compares(i1 %cmp1, i1 %cmp2)
64 define i1 @alloca_argument_compare_escaped_through_store(i64* %arg, i64** %ptr) {
66 %cmp = icmp eq i64* %alloc, %arg
67 %p = getelementptr i64, i64* %alloc, i64 1
68 store i64* %p, i64** %ptr
70 ; CHECK-LABEL: alloca_argument_compare_escaped_through_store
71 ; CHECK: %cmp = icmp eq i64* %alloc, %arg
75 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
76 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
77 define i1 @alloca_argument_compare_benign_instrs(i8* %arg) {
79 call void @llvm.lifetime.start.p0i8(i64 1, i8* %alloc)
80 %cmp = icmp eq i8* %arg, %alloc
81 %x = load i8, i8* %arg
82 store i8 %x, i8* %alloc
83 call void @llvm.lifetime.end.p0i8(i64 1, i8* %alloc)
85 ; CHECK-LABEL: alloca_argument_compare_benign_instrs
89 declare i64* @allocator()
90 define i1 @alloca_call_compare() {
92 %q = call i64* @allocator()
93 %cmp = icmp eq i64* %p, %q
95 ; CHECK-LABEL: alloca_call_compare