@@ -52,6 +52,16 @@ bool hasConstZero(const OpFoldResult ofr) {
5252 return false ;
5353}
5454
55+ Value ofrToValue (const OpFoldResult ofr, const Location loc, OpBuilder &b) {
56+ if (Value val = dyn_cast<Value>(ofr)) {
57+ return val;
58+ }
59+
60+ auto attr = dyn_cast<Attribute>(ofr);
61+ auto typedAttr = dyn_cast<TypedAttr>(attr);
62+ return b.create <arith::ConstantOp>(loc, typedAttr);
63+ }
64+
5565Value ofrToIndexValue (const OpFoldResult ofr, const Location loc,
5666 OpBuilder &b) {
5767 if (Value val = dyn_cast<Value>(ofr)) {
@@ -344,17 +354,8 @@ OpFoldResult selectOFRs(const OpFoldResult condOFR, const OpFoldResult trueOFR,
344354 OpBuilder &b) {
345355 auto trueValue = ofrToIndexValue (trueOFR, loc, b);
346356 auto falseValue = ofrToIndexValue (falseOFR, loc, b);
347- auto condValue = ofrToIndexValue (condOFR, loc, b);
348-
349- // Ideally we should not be passing around everything as index type since mask
350- // analysis can come across i1 values, but that improvement is being left for
351- // future work. For now we just unwrap an index back into it's i1 value if
352- // necessary.
353- if (!condValue.getType ().isInteger (1 )) {
354- assert (condValue.getDefiningOp <arith::IndexCastOp>());
355- condValue = condValue.getDefiningOp <arith::IndexCastOp>().getOperand ();
356- assert (condValue.getType ().isInteger (1 ));
357- }
357+ auto condValue = ofrToValue (condOFR, loc, b);
358+ assert (condValue.getType ().isInteger (1 ) && " Condition for selectOp must be a bool type" );
358359
359360 auto selectOp =
360361 b.create <arith::SelectOp>(loc, condValue, trueValue, falseValue);
0 commit comments