diff --git a/llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp b/llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp --- a/llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp @@ -1295,7 +1295,13 @@ std::optional FalseDiff = getConstantOffset(SelectA->getFalseValue(), SelectB->getFalseValue(), ContextInst, Depth); - if (TrueDiff == FalseDiff) + // A bit unclear how we can get TrueDiff and FalseDiff with different bit + // widths, since the bit width returned by getConstantOffset is determined + // by the datatype of the pointer, and both sides of the `select` should + // have the same datatype. But we seem to be hitting this in practice. + if (FalseDiff.has_value() && + TrueDiff->getBitWidth() == FalseDiff->getBitWidth() && + TrueDiff == FalseDiff) return TrueDiff; } }