1 ; RUN: opt -instsimplify -S < %s | FileCheck %s
2 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3 target triple = "x86_64-unknown-linux-gnu"
5 @g1 = global i32 0, align 4
7 ; Make sure we can simplify away a pointer comparison between
8 ; dynamically-allocated memory and a local stack allocation.
13 ; mData = new int[12];
14 ; if (mData != mStackData) {
19 define void @_Z2p1v() #0 {
20 %mStackData = alloca [10 x i32], align 16
21 %1 = bitcast [10 x i32]* %mStackData to i8*
22 %2 = tail call noalias i8* @_Znam(i64 48) #4
23 %3 = bitcast i8* %2 to i32*
24 %4 = getelementptr inbounds [10 x i32]* %mStackData, i64 0, i64 0
25 %5 = icmp eq i32* %3, %4
26 br i1 %5, label %7, label %6
28 ; CHECK-LABEL: @_Z2p1v
32 ; <label>:6 ; preds = %0
33 call void @_ZdaPv(i8* %2) #5
36 ; <label>:7 ; preds = %0, %6
40 ; Also check a more-complicated case with multiple underlying objects.
42 define void @_Z2p2bb(i1 zeroext %b1, i1 zeroext %b2) #0 {
43 %mStackData = alloca [10 x i32], align 16
44 %1 = bitcast [10 x i32]* %mStackData to i8*
45 %2 = getelementptr inbounds [10 x i32]* %mStackData, i64 0, i64 0
46 %3 = select i1 %b1, i32* %2, i32* @g1
47 %4 = tail call noalias i8* @_Znam(i64 48) #4
48 %5 = tail call noalias i8* @_Znam(i64 48) #4
49 %.v = select i1 %b2, i8* %4, i8* %5
50 %6 = bitcast i8* %.v to i32*
51 %7 = icmp eq i32* %6, %3
52 br i1 %7, label %9, label %8
54 ; CHECK-LABEL: @_Z2p2bb
58 ; <label>:8 ; preds = %0
59 call void @_ZdaPv(i8* %4) #5
60 call void @_ZdaPv(i8* %5) #5
63 ; <label>:9 ; preds = %0, %8
67 ; Here's another case involving multiple underlying objects, but this time we
68 ; must keep the comparison (it might involve a regular pointer-typed function
71 define void @_Z4nopebbPi(i1 zeroext %b1, i1 zeroext %b2, i32* readnone %q) #0 {
72 %mStackData = alloca [10 x i32], align 16
73 %1 = bitcast [10 x i32]* %mStackData to i8*
74 %2 = getelementptr inbounds [10 x i32]* %mStackData, i64 0, i64 0
75 %3 = select i1 %b1, i32* %2, i32* %q
76 %4 = tail call noalias i8* @_Znam(i64 48) #4
77 %5 = tail call noalias i8* @_Znam(i64 48) #4
78 %.v = select i1 %b2, i8* %4, i8* %5
79 %6 = bitcast i8* %.v to i32*
80 %7 = icmp eq i32* %6, %3
81 br i1 %7, label %9, label %8
83 ; CHECK-LABEL: @_Z4nopebbPi
87 ; <label>:8 ; preds = %0
88 call void @_ZdaPv(i8* %4) #5
89 call void @_ZdaPv(i8* %5) #5
92 ; <label>:9 ; preds = %0, %8
96 ; Function Attrs: nobuiltin
97 declare noalias i8* @_Znam(i64) #2
99 ; Function Attrs: nobuiltin nounwind
100 declare void @_ZdaPv(i8*) #3
102 attributes #0 = { uwtable }
103 attributes #1 = { nounwind }
104 attributes #2 = { nobuiltin }
105 attributes #3 = { nobuiltin nounwind }
106 attributes #4 = { builtin }
107 attributes #5 = { builtin nounwind }