1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=gvn < %s | FileCheck %s
4 ; Phi translation of %gep.j cannot use %gep.i, which is located in a context
5 ; where %i != 0, and would result in incorrect NoAlias results in a context
6 ; where %i == 0 may hold.
8 define i32 @test(i64 %i, i1 %c1, i1 %c2) {
11 ; CHECK-NEXT: [[PTR:%.*]] = alloca [2 x i32], align 4
12 ; CHECK-NEXT: br i1 [[C1:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
14 ; CHECK-NEXT: br i1 [[C2:%.*]], label [[IF2:%.*]], label [[ELSE2:%.*]]
16 ; CHECK-NEXT: store i32 1, ptr [[PTR]], align 4
17 ; CHECK-NEXT: [[GEP_J_PHI_TRANS_INSERT:%.*]] = getelementptr inbounds i32, ptr [[PTR]], i64 [[I:%.*]]
18 ; CHECK-NEXT: [[V_PRE:%.*]] = load i32, ptr [[GEP_J_PHI_TRANS_INSERT]], align 4
19 ; CHECK-NEXT: br label [[JOIN:%.*]]
21 ; CHECK-NEXT: store i32 2, ptr [[PTR]], align 4
22 ; CHECK-NEXT: br label [[JOIN]]
24 ; CHECK-NEXT: [[V:%.*]] = phi i32 [ [[V_PRE]], [[IF2]] ], [ 2, [[ELSE2]] ]
25 ; CHECK-NEXT: [[J:%.*]] = phi i64 [ [[I]], [[IF2]] ], [ 0, [[ELSE2]] ]
26 ; CHECK-NEXT: [[GEP_J:%.*]] = getelementptr inbounds i32, ptr [[PTR]], i64 [[J]]
27 ; CHECK-NEXT: ret i32 [[V]]
29 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i64 [[I]], 0
30 ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
31 ; CHECK-NEXT: [[GEP_I:%.*]] = getelementptr inbounds i32, ptr [[PTR]], i64 [[I]]
32 ; CHECK-NEXT: ret i32 0
35 %ptr = alloca [2 x i32]
36 br i1 %c1, label %if, label %else
39 br i1 %c2, label %if2, label %else2
50 %j = phi i64 [ %i, %if2 ], [ 0, %else2 ]
51 %gep.j = getelementptr inbounds i32, ptr %ptr, i64 %j
52 %v = load i32, ptr %gep.j
56 %cmp = icmp ne i64 %i, 0
57 call void @llvm.assume(i1 %cmp)
58 %gep.i = getelementptr inbounds i32, ptr %ptr, i64 %i
62 declare void @llvm.assume(i1)