1; RUN: opt -codegenprepare < %s -S | FileCheck %s
2
3target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
4target triple = "aarch64--linux-gnu"
5
6%struct.match_state = type { i64, i64  }
7
8; %add is also promoted by forking an extra sext.
9define void @promoteTwoOne(i32 %i, i32 %j, i64* %P1, i64* %P2 ) {
10; CHECK-LABEL: @promoteTwoOne
11; CHECK-LABEL: entry:
12; CHECK: %[[SEXT1:.*]] = sext i32 %i to i64
13; CHECK: %[[SEXT2:.*]] = sext i32 %j to i64
14; CHECK: %add = add nsw i64 %[[SEXT1]], %[[SEXT2]]
15entry:
16  %add = add nsw i32 %i, %j
17  %s = sext i32 %add to i64
18  %addr1 = getelementptr inbounds i64, i64* %P1, i64 %s
19  store i64 %s, i64* %addr1
20  %s2 = sext i32 %i to i64
21  %addr2 = getelementptr inbounds i64, i64* %P2, i64 %s2
22  store i64 %s2, i64* %addr2
23  ret void
24}
25
26; Both %add1 and %add2 are promoted by forking extra sexts.
27define void @promoteTwoTwo(i32 %i, i32 %j, i32 %k, i64* %P1, i64* %P2) {
28; CHECK-LABEL: @promoteTwoTwo
29; CHECK-LABEL:entry:
30; CHECK: %[[SEXT1:.*]] = sext i32 %j to i64
31; CHECK: %[[SEXT2:.*]]  = sext i32 %i to i64
32; CHECK: %add1 = add nsw i64 %[[SEXT1]], %[[SEXT2]]
33; CHECK: %[[SEXT3:.*]] = sext i32 %k to i64
34; CHECK: %add2 = add nsw i64 %[[SEXT1]], %[[SEXT3]]
35entry:
36  %add1 = add nsw i32 %j, %i
37  %s = sext i32 %add1 to i64
38  %addr1 = getelementptr inbounds i64, i64* %P1, i64 %s
39  store i64 %s, i64* %addr1
40  %add2 = add nsw i32 %j, %k
41  %s2 = sext i32 %add2 to i64
42  %addr2 = getelementptr inbounds i64, i64* %P2, i64 %s2
43  store i64 %s2, i64* %addr2
44  ret void
45}
46
47define i64 @promoteGEPSunk(i1 %cond, i64* %base, i32 %i) {
48; CHECK-LABEL: @promoteGEPSunk
49; CHECK-LABEL: entry:
50; CHECK:  %[[SEXT:.*]] = sext i32 %i to i64
51; CHECK:  %add = add nsw i64 %[[SEXT]], 1
52; CHECK:  %add2 = add nsw i64 %[[SEXT]], 2
53entry:
54  %add = add nsw i32 %i, 1
55  %s = sext i32 %add to i64
56  %addr = getelementptr inbounds i64, i64* %base, i64 %s
57  %add2 = add nsw i32 %i,  2
58  %s2 = sext i32 %add2 to i64
59  %addr2 = getelementptr inbounds i64, i64* %base, i64 %s2
60  br i1 %cond, label %if.then, label %if.then2
61if.then:
62  %v = load i64, i64* %addr
63  %v2 = load i64, i64* %addr2
64  %r = add i64 %v, %v2
65  ret i64 %r
66if.then2:
67  ret i64 0;
68}
69