1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 %"struct.std::complex" = type { { float, float } }
5 @dd = external global %"struct.std::complex", align 4
6 @dd2 = external global %"struct.std::complex", align 4
8 define void @_Z3fooi(i32 signext %n) {
9 ; CHECK-LABEL: @_Z3fooi(
11 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
13 ; CHECK-NEXT: [[TMP0:%.*]] = phi float [ 0.000000e+00, [[ENTRY:%.*]] ], [ [[ADD_I:%.*]], [[FOR_BODY:%.*]] ]
14 ; CHECK-NEXT: [[TMP1:%.*]] = phi float [ 0.000000e+00, [[ENTRY]] ], [ [[ADD4_I:%.*]], [[FOR_BODY]] ]
15 ; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[INC:%.*]], [[FOR_BODY]] ]
16 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_0]], [[N:%.*]]
17 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END:%.*]]
19 ; CHECK-NEXT: [[TMP2:%.*]] = load float, float* getelementptr inbounds (%"struct.std::complex", %"struct.std::complex"* @dd, i64 0, i32 0, i32 0), align 4
20 ; CHECK-NEXT: [[TMP3:%.*]] = load float, float* getelementptr inbounds (%"struct.std::complex", %"struct.std::complex"* @dd, i64 0, i32 0, i32 1), align 4
21 ; CHECK-NEXT: [[TMP4:%.*]] = load float, float* getelementptr inbounds (%"struct.std::complex", %"struct.std::complex"* @dd2, i64 0, i32 0, i32 0), align 4
22 ; CHECK-NEXT: [[TMP5:%.*]] = load float, float* getelementptr inbounds (%"struct.std::complex", %"struct.std::complex"* @dd2, i64 0, i32 0, i32 1), align 4
23 ; CHECK-NEXT: [[MUL_I:%.*]] = fmul float [[TMP2]], [[TMP4]]
24 ; CHECK-NEXT: [[MUL4_I:%.*]] = fmul float [[TMP3]], [[TMP5]]
25 ; CHECK-NEXT: [[SUB_I:%.*]] = fsub float [[MUL_I]], [[MUL4_I]]
26 ; CHECK-NEXT: [[MUL5_I:%.*]] = fmul float [[TMP3]], [[TMP4]]
27 ; CHECK-NEXT: [[MUL6_I:%.*]] = fmul float [[TMP2]], [[TMP5]]
28 ; CHECK-NEXT: [[ADD_I4:%.*]] = fadd float [[MUL5_I]], [[MUL6_I]]
29 ; CHECK-NEXT: [[ADD_I]] = fadd float [[SUB_I]], [[TMP0]]
30 ; CHECK-NEXT: [[ADD4_I]] = fadd float [[ADD_I4]], [[TMP1]]
31 ; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_0]], 1
32 ; CHECK-NEXT: br label [[FOR_COND]]
34 ; CHECK-NEXT: store float [[TMP0]], float* getelementptr inbounds (%"struct.std::complex", %"struct.std::complex"* @dd, i64 0, i32 0, i32 0), align 4
35 ; CHECK-NEXT: store float [[TMP1]], float* getelementptr inbounds (%"struct.std::complex", %"struct.std::complex"* @dd, i64 0, i32 0, i32 1), align 4
36 ; CHECK-NEXT: ret void
42 %ldd.sroa.0.0 = phi i32 [ 0, %entry ], [ %5, %for.body ]
43 %ldd.sroa.6.0 = phi i32 [ 0, %entry ], [ %7, %for.body ]
44 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
45 %cmp = icmp slt i32 %i.0, %n
46 br i1 %cmp, label %for.body, label %for.end
49 %0 = load float, float* getelementptr inbounds (%"struct.std::complex", %"struct.std::complex"* @dd, i64 0, i32 0, i32 0), align 4
50 %1 = load float, float* getelementptr inbounds (%"struct.std::complex", %"struct.std::complex"* @dd, i64 0, i32 0, i32 1), align 4
51 %2 = load float, float* getelementptr inbounds (%"struct.std::complex", %"struct.std::complex"* @dd2, i64 0, i32 0, i32 0), align 4
52 %3 = load float, float* getelementptr inbounds (%"struct.std::complex", %"struct.std::complex"* @dd2, i64 0, i32 0, i32 1), align 4
53 %mul.i = fmul float %0, %2
54 %mul4.i = fmul float %1, %3
55 %sub.i = fsub float %mul.i, %mul4.i
56 %mul5.i = fmul float %1, %2
57 %mul6.i = fmul float %0, %3
58 %add.i4 = fadd float %mul5.i, %mul6.i
59 %4 = bitcast i32 %ldd.sroa.0.0 to float
60 %add.i = fadd float %sub.i, %4
61 %5 = bitcast float %add.i to i32
62 %6 = bitcast i32 %ldd.sroa.6.0 to float
63 %add4.i = fadd float %add.i4, %6
64 %7 = bitcast float %add4.i to i32
65 %inc = add nsw i32 %i.0, 1
69 store i32 %ldd.sroa.0.0, i32* bitcast (%"struct.std::complex"* @dd to i32*), align 4
70 store i32 %ldd.sroa.6.0, i32* bitcast (float* getelementptr inbounds (%"struct.std::complex", %"struct.std::complex"* @dd, i64 0, i32 0, i32 1) to i32*), align 4
76 define void @multi_phi(i32 signext %n) {
77 ; CHECK-LABEL: @multi_phi(
79 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
81 ; CHECK-NEXT: [[TMP0:%.*]] = phi float [ 0.000000e+00, [[ENTRY:%.*]] ], [ [[TMP6:%.*]], [[ODD_BB:%.*]] ]
82 ; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[INC:%.*]], [[ODD_BB]] ]
83 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_0]], [[N:%.*]]
84 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
86 ; CHECK-NEXT: [[TMP1:%.*]] = load float, float* getelementptr inbounds (%"struct.std::complex", %"struct.std::complex"* @dd, i64 0, i32 0, i32 0), align 4
87 ; CHECK-NEXT: [[TMP2:%.*]] = load float, float* getelementptr inbounds (%"struct.std::complex", %"struct.std::complex"* @dd, i64 0, i32 0, i32 1), align 4
88 ; CHECK-NEXT: [[TMP3:%.*]] = load float, float* getelementptr inbounds (%"struct.std::complex", %"struct.std::complex"* @dd2, i64 0, i32 0, i32 0), align 4
89 ; CHECK-NEXT: [[TMP4:%.*]] = load float, float* getelementptr inbounds (%"struct.std::complex", %"struct.std::complex"* @dd2, i64 0, i32 0, i32 1), align 4
90 ; CHECK-NEXT: [[MUL_I:%.*]] = fmul float [[TMP1]], [[TMP3]]
91 ; CHECK-NEXT: [[MUL4_I:%.*]] = fmul float [[TMP2]], [[TMP4]]
92 ; CHECK-NEXT: [[SUB_I:%.*]] = fsub float [[MUL_I]], [[MUL4_I]]
93 ; CHECK-NEXT: [[ADD_I:%.*]] = fadd float [[SUB_I]], [[TMP0]]
94 ; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_0]], 1
95 ; CHECK-NEXT: [[BIT0:%.*]] = and i32 [[INC]], 1
96 ; CHECK-NEXT: [[EVEN:%.*]] = icmp eq i32 [[BIT0]], 0
97 ; CHECK-NEXT: br i1 [[EVEN]], label [[EVEN_BB:%.*]], label [[ODD_BB]]
99 ; CHECK-NEXT: [[TMP5:%.*]] = fadd float [[SUB_I]], [[ADD_I]]
100 ; CHECK-NEXT: br label [[ODD_BB]]
102 ; CHECK-NEXT: [[TMP6]] = phi float [ [[ADD_I]], [[FOR_BODY]] ], [ [[TMP5]], [[EVEN_BB]] ]
103 ; CHECK-NEXT: br label [[FOR_COND]]
105 ; CHECK-NEXT: store float [[TMP0]], float* getelementptr inbounds (%"struct.std::complex", %"struct.std::complex"* @dd, i64 0, i32 0, i32 0), align 4
106 ; CHECK-NEXT: ret void
112 %ldd.sroa.0.0 = phi i32 [ 0, %entry ], [ %9, %odd.bb ]
113 %i.0 = phi i32 [ 0, %entry ], [ %inc, %odd.bb ]
114 %cmp = icmp slt i32 %i.0, %n
115 br i1 %cmp, label %for.body, label %for.end
118 %0 = load float, float* getelementptr inbounds (%"struct.std::complex", %"struct.std::complex"* @dd, i64 0, i32 0, i32 0), align 4
119 %1 = load float, float* getelementptr inbounds (%"struct.std::complex", %"struct.std::complex"* @dd, i64 0, i32 0, i32 1), align 4
120 %2 = load float, float* getelementptr inbounds (%"struct.std::complex", %"struct.std::complex"* @dd2, i64 0, i32 0, i32 0), align 4
121 %3 = load float, float* getelementptr inbounds (%"struct.std::complex", %"struct.std::complex"* @dd2, i64 0, i32 0, i32 1), align 4
122 %mul.i = fmul float %0, %2
123 %mul4.i = fmul float %1, %3
124 %sub.i = fsub float %mul.i, %mul4.i
125 %4 = bitcast i32 %ldd.sroa.0.0 to float
126 %add.i = fadd float %sub.i, %4
127 %5 = bitcast float %add.i to i32
128 %inc = add nsw i32 %i.0, 1
129 %bit0 = and i32 %inc, 1
130 %even = icmp slt i32 %bit0, 1
131 br i1 %even, label %even.bb, label %odd.bb
134 %6 = bitcast i32 %5 to float
135 %7 = fadd float %sub.i, %6
136 %8 = bitcast float %7 to i32
140 %9 = phi i32 [ %5, %for.body ], [ %8, %even.bb ]
144 store i32 %ldd.sroa.0.0, i32* bitcast (%"struct.std::complex"* @dd to i32*), align 4