diff --git a/lib/Tools/LinearLayout.cpp b/lib/Tools/LinearLayout.cpp index eddfec16a87b..1f28cbd5ec91 100644 --- a/lib/Tools/LinearLayout.cpp +++ b/lib/Tools/LinearLayout.cpp @@ -121,6 +121,11 @@ getInjectiveMat(const LinearLayout &layout) { // outDim as columns. In other words, finds the number of linearly-independent // bases for this output dimension. int getMatrixRank(std::unique_ptr m, int numRows, int numCols) { + // f2reduce underflows if the number of cols is 0, return the rank early in + // this case. + if (numCols == 0) { + return 0; + } // stride is specified in number of 64-bit words per row, and we pack our // matrix so that there's only one uint64_t per row. assert(numCols <= 64);