diff --git a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp
--- a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp
+++ b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp
@@ -1205,9 +1205,15 @@
     return op.emitOpError() << "requires attribute's type (" << value.getType()
                             << ") to match op's return type (" << type << ")";
 
-  if (type.isa<IndexType>() || value.isa<BoolAttr>())
+  if (value.isa<BoolAttr>())
     return success();
 
+  if (type.isa<IndexType>()) {
+    if (!value.isa<IntegerAttr>())
+      return op.emitOpError("requires 'value' to be an integer constant");
+    return success();
+  }
+
   if (auto intAttr = value.dyn_cast<IntegerAttr>()) {
     IntegerType intType = type.cast<IntegerType>();
     if (!intType.isSignless())