Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/SCF/Utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ LogicalResult mlir::loopUnrollFull(scf::ForOp forOp) {
std::optional<APInt> mayBeConstantTripCount = forOp.getStaticTripCount();
if (!mayBeConstantTripCount.has_value())
return failure();
APInt &tripCount = *mayBeConstantTripCount;
const APInt &tripCount = *mayBeConstantTripCount;
if (tripCount.isZero())
return success();
if (tripCount.getSExtValue() == 1)
Expand Down
36 changes: 19 additions & 17 deletions mlir/lib/Dialect/Utils/StaticValueUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//

#include "mlir/Dialect/Utils/StaticValueUtils.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/Matchers.h"
#include "mlir/Support/LLVM.h"
#include "llvm/ADT/APSInt.h"
Expand Down Expand Up @@ -280,27 +281,28 @@ std::optional<APInt> constantTripCount(
computeUbMinusLb) {
// This is the bitwidth used to return 0 when loop does not execute.
// We infer it from the type of the bound if it isn't an index type.
bool isIndex = true;
auto getBitwidth = [&](OpFoldResult ofr) -> int {
if (auto attr = dyn_cast<Attribute>(ofr)) {
if (auto intAttr = dyn_cast<IntegerAttr>(attr)) {
if (auto intType = dyn_cast<IntegerType>(intAttr.getType())) {
isIndex = intType.isIndex();
return intType.getWidth();
}
}
auto getBitwidth = [&](OpFoldResult ofr) -> std::tuple<int, bool> {
if (auto intAttr =
dyn_cast_or_null<IntegerAttr>(dyn_cast<Attribute>(ofr))) {
if (auto intType = dyn_cast<IntegerType>(intAttr.getType()))
return std::make_tuple(intType.getWidth(), intType.isIndex());
} else {
auto val = cast<Value>(ofr);
if (auto intType = dyn_cast<IntegerType>(val.getType())) {
isIndex = intType.isIndex();
return intType.getWidth();
}
if (auto intType = dyn_cast<IntegerType>(val.getType()))
return std::make_tuple(intType.getWidth(), intType.isIndex());
}
return IndexType::kInternalStorageBitWidth;
return std::make_tuple(IndexType::kInternalStorageBitWidth, true);
};
int bitwidth = getBitwidth(lb);
assert(bitwidth == getBitwidth(ub) &&
"lb and ub must have the same bitwidth");
auto [bitwidth, isIndex] = getBitwidth(lb);
// This would better be an assert, but unfortunately it breaks scf.for_all
// which is missing attributes and SSA value optionally for its bounds, and
// uses Index type for the dynamic bounds but i64 for the static bounds. This
// is broken...
if (std::tie(bitwidth, isIndex) != getBitwidth(ub)) {
LDBG() << "mismatch between lb and ub bitwidth/type: " << ub << " vs "
<< lb;
return std::nullopt;
}
if (lb == ub)
return APInt(bitwidth, 0);

Expand Down