llvm.org GIT mirror llvm / 4b3f6b4
Merging r236457 and r236635: ------------------------------------------------------------------------ r236457 | tnorthover | 2015-05-04 13:41:51 -0700 (Mon, 04 May 2015) | 9 lines CodeGen: match up correct insertvalue indices when assessing tail calls. When deciding whether a value comes from the aggregate or inserted value of an insertvalue instruction, we compare the indices against those of the location we're interested in. One of the lists needs reversing because the input data is backwards (so that modifications take place at the end of the SmallVector), but we were reversing both before leading to incorrect results. ------------------------------------------------------------------------ r236635 | tnorthover | 2015-05-06 13:07:38 -0700 (Wed, 06 May 2015) | 12 lines CodeGen: move over-zealous assert into actual if statement. It's quite possible to encounter an insertvalue instruction that's more deeply nested than the value we're looking for, but when that happens we really mustn't compare beyond the end of the index array. Since I couldn't see any guarantees about what comparisons std::equal makes, we probably need to directly check the size beforehand. In practice, I suspect most std::equal implementations would probably bail early, which would be OK. But just in case... rdar://20834485 git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_36@239611 91177308-0d34-0410-b5e6-96231b3b80d8 Tim Northover 4 years ago
2 changed file(s) with 40 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
294294 } else if (const InsertValueInst *IVI = dyn_cast(V)) {
295295 // Value may come from either the aggregate or the scalar
296296 ArrayRef InsertLoc = IVI->getIndices();
297 if (std::equal(InsertLoc.rbegin(), InsertLoc.rend(),
298 ValLoc.rbegin())) {
297 if (ValLoc.size() >= InsertLoc.size() &&
298 std::equal(InsertLoc.begin(), InsertLoc.end(), ValLoc.rbegin())) {
299299 // The type being inserted is a nested sub-type of the aggregate; we
300300 // have to remove those initial indices to get the location we're
301301 // interested in for the operand.
102102 tail call void @callee_weak()
103103 ret void
104104 }
105
106 declare { [2 x float] } @get_vec2()
107
108 define { [3 x float] } @test_add_elem() {
109 ; CHECK-LABEL: test_add_elem:
110 ; CHECK: bl get_vec2
111 ; CHECK: fmov s2, #1.0
112 ; CHECK: ret
113
114 %call = tail call { [2 x float] } @get_vec2()
115 %arr = extractvalue { [2 x float] } %call, 0
116 %arr.0 = extractvalue [2 x float] %arr, 0
117 %arr.1 = extractvalue [2 x float] %arr, 1
118
119 %res.0 = insertvalue { [3 x float] } undef, float %arr.0, 0, 0
120 %res.01 = insertvalue { [3 x float] } %res.0, float %arr.1, 0, 1
121 %res.012 = insertvalue { [3 x float] } %res.01, float 1.000000e+00, 0, 2
122 ret { [3 x float] } %res.012
123 }
124
125 declare double @get_double()
126 define { double, [2 x double] } @test_mismatched_insert() {
127 ; CHECK-LABEL: test_mismatched_insert:
128 ; CHECK: bl get_double
129 ; CHECK: bl get_double
130 ; CHECK: bl get_double
131 ; CHECK: ret
132
133 %val0 = call double @get_double()
134 %val1 = call double @get_double()
135 %val2 = tail call double @get_double()
136
137 %res.0 = insertvalue { double, [2 x double] } undef, double %val0, 0
138 %res.01 = insertvalue { double, [2 x double] } %res.0, double %val1, 1, 0
139 %res.012 = insertvalue { double, [2 x double] } %res.01, double %val2, 1, 1
140
141 ret { double, [2 x double] } %res.012
142 }