This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Avoid crash of UnsignedWhenEquivalent for no integer type.
ClosedPublic

Authored by jacquesguan on Jan 5 2023, 1:14 AM.

Diff Detail

Event Timeline

jacquesguan created this revision.Jan 5 2023, 1:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 5 2023, 1:14 AM
jacquesguan requested review of this revision.Jan 5 2023, 1:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 5 2023, 1:14 AM
mehdi_amini added inline comments.Jan 5 2023, 2:36 AM
mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp
38 ↗(On Diff #486493)

Where is the 0 bit width coming from?

jacquesguan added inline comments.Jan 5 2023, 6:38 PM
mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp
38 ↗(On Diff #486493)
IntegerValueRange IntegerValueRange::getMaxRange(Value value) {
  unsigned width = ConstantIntRanges::getStorageBitwidth(value.getType());
  APInt umin = APInt::getMinValue(width);
  APInt umax = APInt::getMaxValue(width);
  APInt smin = width != 0 ? APInt::getSignedMinValue(width) : umin;
  APInt smax = width != 0 ? APInt::getSignedMaxValue(width) : umax;
  return IntegerValueRange{ConstantIntRanges{umin, umax, smin, smax}};
}

When the type is not Integer or Index, width is 0.

Mogball added inline comments.Jan 6 2023, 11:27 AM
mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp
38 ↗(On Diff #486493)

The result should be set to some invalid state if the operation result type is not integral

Address comment.

remove unused comment.

jacquesguan added inline comments.Jan 8 2023, 6:50 PM
mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp
38 ↗(On Diff #486493)

Done.

Mogball accepted this revision.Jan 9 2023, 12:41 PM
This revision is now accepted and ready to land.Jan 9 2023, 12:41 PM