[TIR] Autocorrect Range min and extent types when possible#15872
[TIR] Autocorrect Range min and extent types when possible#15872kparzysz-quic wants to merge 13 commits intoapache:mainfrom
Conversation
The values of `min` and `extent` in Range should have the same type, but the usage of convenience may often produce type mismatches, for example `Range(0, dim)` will assume int32 for the `min`. These mismatches can then cause hard-to-track errors, in particular assertions in the arithmetic simplifier. This is already done for `For` statement, but not in other places. This patch introduces `DataType::WidestOf` function, that returns the widest type from the given list. It is then used to promote the integer bounds if such widest type exists.
|
In most cases the intention was to construct IRs that have consistent types. So insert casting like How about we do the following things:
|
| * hold all values representable in the other types, or "Void" if | ||
| * such type is not present in the array. | ||
| */ | ||
| static DataType WidestOf(const std::vector<DataType>& types) { |
There was a problem hiding this comment.
is it possible to use template trick or overloading to handle two/three case, mainly avoid the vector passing
There was a problem hiding this comment.
Would std::initializer_list be ok?
Edit: Nevermind, I'll do the template.
Test failing in CI:
```
a = T.Cast("int8", T.tvm_struct_get(args, 0, 12, "int64"))
b = 1
Range(a, b)
```
The value 1 has a type int32 by default, but since we're avoiding extra
casts, the only way to legalize this range is by reducing the extent
to int8.
|
I'm not sure what you think. This is adding a lot of code for a simple thing, but I'm hoping that the extra functions may be useful in other cases as well. |
|
This cannot be done correctly in |
The values of
minandextentin Range should have the same type, but the usage of convenience may often produce type mismatches, for exampleRange(0, dim)will assume int32 for themin. These mismatches can then cause hard-to-track errors, in particular assertions in the arithmetic simplifier.This is already done for
Forstatement, but not in other places.This patch introduces
DataType::WidestOffunction, that returns the widest type from the given list. It is then used to promote the integer bounds if such widest type exists.