================
@@ -256,23 +256,23 @@ static IteratorRange lowerIteratorRange(
   mlir::Value ubVal =
       fir::getBase(converter.genExprValue(toEvExpr(ubExpr), stmtCtx));
 
-  auto toIndex = [](fir::FirOpBuilder &builder, mlir::Location loc,
-                    mlir::Value v) -> mlir::Value {
-    if (v.getType().isIndex())
-      return v;
-    return fir::ConvertOp::create(builder, loc, builder.getIndexType(), v);
-  };
-
-  r.lb = toIndex(builder, loc, lbVal);
-  r.ub = toIndex(builder, loc, ubVal);
-
-  if (stExpr) {
-    mlir::Value stVal =
-        fir::getBase(converter.genExprValue(toEvExpr(*stExpr), stmtCtx));
-    r.step = toIndex(builder, loc, stVal);
-  } else {
-    r.step = mlir::arith::ConstantIndexOp::create(builder, loc, 1);
-  }
+  // Begin and end take the iterator's type, but the step keeps its own. Count
+  // in the wider of the two so that neither is narrowed.
+  mlir::Type ivTy = converter.genType(*r.ivSym);
+  mlir::Value stVal =
+      stExpr ? fir::getBase(converter.genExprValue(toEvExpr(*stExpr), stmtCtx))
+             : builder.createIntegerConstant(loc, ivTy, 1);
+  mlir::Type rangeTy = ivTy;
+  if (auto stTy = mlir::dyn_cast<mlir::IntegerType>(stVal.getType()))
+    if (stTy.isSignless() &&
+        stTy.getWidth() > mlir::cast<mlir::IntegerType>(ivTy).getWidth())
+      rangeTy = stTy;
+
+  r.lb = builder.createConvert(loc, rangeTy,
+                               builder.createConvert(loc, ivTy, lbVal));
+  r.ub = builder.createConvert(loc, rangeTy,
+                               builder.createConvert(loc, ivTy, ubVal));
----------------
chichunchen wrote:

Thanks. Each range is now built in the widest of the iterator, begin, end and 
step types, and only the induction value is narrowed to the iterator kind when 
it's stored.

https://github.com/llvm/llvm-project/pull/227454
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to