1 ; RUN: opt -gvn -S < %s | FileCheck %s
3 declare noalias i8* @malloc(i64)
5 ; Detecting that %s is fully redundant should let us detect that %w is partially
7 define void @fn1(i32** noalias %start, i32* %width, i32 %h) {
10 %call = tail call noalias i8* @malloc(i64 1024)
11 %call.cast = bitcast i8* %call to i32*
12 store i32* %call.cast, i32** %start, align 8
16 %cmp = icmp slt i32 1, %h
17 br i1 %cmp, label %body, label %exit
19 ; CHECK-LABEL: preheader.body_crit_edge:
20 ; CHECK: load i32, i32* %width, align 8
23 ; CHECK-NOT: load i32*, i32** %start, align 8
24 ; CHECK-NOT: load i32, i32* %width, align 8
26 %j = phi i32 [ 0, %preheader ], [ %j.next, %body ]
27 %s = load i32*, i32** %start, align 8
28 %idx = getelementptr inbounds i32, i32* %s, i64 0
29 store i32 0, i32* %idx, align 4
30 %j.next = add nuw nsw i32 %j, 1
31 %w = load i32, i32* %width, align 8
32 %cmp3 = icmp slt i32 %j.next, %w
33 br i1 %cmp3, label %body, label %preheader
39 ; %s is fully redundant but has more than one available value. Detecting that
40 ; %w is partially redundant requires alias analysis that can analyze those
42 define void @fn2(i32** noalias %start, i32* %width, i32 %h, i32 %arg) {
45 %call = tail call noalias i8* @malloc(i64 1024)
46 %call.cast = bitcast i8* %call to i32*
47 %cmp1 = icmp slt i32 %arg, 0
48 br i1 %cmp1, label %if, label %else
51 store i32* %call.cast, i32** %start, align 8
55 %gep = getelementptr inbounds i32, i32* %call.cast, i32 %arg
56 store i32* %gep, i32** %start, align 8
59 ; CHECK-LABEL: preheader:
60 ; CHECK: %s = phi i32* [ %s, %body ], [ %gep, %else ], [ %call.cast, %if ]
63 %cmp = icmp slt i32 1, %h
64 br i1 %cmp, label %body, label %exit
66 ; CHECK-LABEL: preheader.body_crit_edge:
67 ; CHECK: load i32, i32* %width, align 8
70 ; CHECK-NOT: load i32*, i32** %start, align 8
71 ; CHECK-NOT: load i32, i32* %width, align 8
73 %j = phi i32 [ 0, %preheader ], [ %j.next, %body ]
74 %s = load i32*, i32** %start, align 8
75 %idx = getelementptr inbounds i32, i32* %s, i64 0
76 store i32 0, i32* %idx, align 4
77 %j.next = add nuw nsw i32 %j, 1
78 %w = load i32, i32* %width, align 8
79 %cmp3 = icmp slt i32 %j.next, %w
80 br i1 %cmp3, label %body, label %preheader