Skip to content

Commit cf7ad9c

Browse files
committed
more comments
1 parent 3534df9 commit cf7ad9c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

mlir/include/mlir/Interfaces/InferIntRangeInterface.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,14 @@ class ConstantIntRanges {
103103
/// value.
104104
std::optional<APInt> getConstantValue() const;
105105

106-
/// Returns true if signed range is poisoned, i.e. no valid signed value
107-
/// can be represented.
106+
/// Returns true if signed range is poisoned, poisoned ranges are propagated
107+
/// through the DAG and will cause the immediate UB if reached the
108+
/// side-effecting operation.
108109
bool isSignedPoison() const;
109110

110-
/// Returns true if unsigned range is poisoned, i.e. no valid unsigned value
111-
/// can be represented.
111+
/// Returns true if unsigned range is poisoned, poisoned ranges are propagated
112+
/// through the DAG and will cause the immediate UB if reached the
113+
/// side-effecting operation.
112114
bool isUnsignedPoison() const;
113115

114116
friend raw_ostream &operator<<(raw_ostream &os,

mlir/lib/Interfaces/InferIntRangeInterface.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ ConstantIntRanges::rangeUnion(const ConstantIntRanges &other) const {
112112
APInt sminUnion;
113113
APInt smaxUnion;
114114

115+
// Union of poisoned range with any other range is the other range.
116+
// Union is used when we need to merge ranges from multiple indepdenent
117+
// sources, e.g. in `arith.select` or CFG merge. "Observing" a poisoned
118+
// value (using it in side-effecting operation) will cause the immediate UB.
119+
// Well-formed programs should never observe the immediate UB so we assume
120+
// result is either unused or only used in circumstances when it received the
121+
// non-poisoned argument.
115122
if (isUnsignedPoison()) {
116123
uminUnion = other.umin();
117124
umaxUnion = other.umax();
@@ -151,6 +158,7 @@ ConstantIntRanges::intersection(const ConstantIntRanges &other) const {
151158
APInt sminIntersect;
152159
APInt smaxIntersect;
153160

161+
// Intersection of poisoned range with any other range is poisoned.
154162
if (isUnsignedPoison()) {
155163
uminIntersect = umin();
156164
umaxIntersect = umax();

0 commit comments

Comments
 (0)