@@ -93,8 +93,12 @@ Attribute constFoldBinaryOpConditional(ArrayRef<Attribute> operands,
93
93
if (lhs.getType () != rhs.getType ())
94
94
return {};
95
95
96
- auto lhsIt = lhs.value_begin <ElementValueT>();
97
- auto rhsIt = rhs.value_begin <ElementValueT>();
96
+ auto maybeLhsIt = lhs.try_value_begin <ElementValueT>();
97
+ auto maybeRhsIt = rhs.try_value_begin <ElementValueT>();
98
+ if (!maybeLhsIt || !maybeRhsIt)
99
+ return {};
100
+ auto lhsIt = *maybeLhsIt;
101
+ auto rhsIt = *maybeRhsIt;
98
102
SmallVector<ElementValueT, 4 > elementResults;
99
103
elementResults.reserve (lhs.getNumElements ());
100
104
for (size_t i = 0 , e = lhs.getNumElements (); i < e; ++i, ++lhsIt, ++rhsIt) {
@@ -227,7 +231,10 @@ Attribute constFoldUnaryOpConditional(ArrayRef<Attribute> operands,
227
231
// expanding the values.
228
232
auto op = cast<ElementsAttr>(operands[0 ]);
229
233
230
- auto opIt = op.value_begin <ElementValueT>();
234
+ auto maybeOpIt = op.try_value_begin <ElementValueT>();
235
+ if (!maybeOpIt)
236
+ return {};
237
+ auto opIt = *maybeOpIt;
231
238
SmallVector<ElementValueT> elementResults;
232
239
elementResults.reserve (op.getNumElements ());
233
240
for (size_t i = 0 , e = op.getNumElements (); i < e; ++i, ++opIt) {
@@ -293,12 +300,14 @@ Attribute constFoldCastOp(ArrayRef<Attribute> operands, Type resType,
293
300
return {};
294
301
return DenseElementsAttr::get (cast<ShapedType>(resType), elementResult);
295
302
}
296
- if (isa <ElementsAttr>(operands[0 ])) {
303
+ if (auto op = dyn_cast <ElementsAttr>(operands[0 ])) {
297
304
// Operand is ElementsAttr-derived; perform an element-wise fold by
298
305
// expanding the value.
299
- auto op = cast<ElementsAttr>(operands[0 ]);
300
306
bool castStatus = true ;
301
- auto opIt = op.value_begin <ElementValueT>();
307
+ auto maybeOpIt = op.try_value_begin <ElementValueT>();
308
+ if (!maybeOpIt)
309
+ return {};
310
+ auto opIt = *maybeOpIt;
302
311
SmallVector<TargetElementValueT> elementResults;
303
312
elementResults.reserve (op.getNumElements ());
304
313
for (size_t i = 0 , e = op.getNumElements (); i < e; ++i, ++opIt) {
0 commit comments