Skip to content

[GlobalOpt][Flow][Quant] Fix segfault on unlowered quant.uniform types - #24824

Open
FedericoBruzzone wants to merge 3 commits into
iree-org:mainfrom
FedericoBruzzone:fix-hoistable-quant-type-segfault
Open

[GlobalOpt][Flow][Quant] Fix segfault on unlowered quant.uniform types#24824
FedericoBruzzone wants to merge 3 commits into
iree-org:mainfrom
FedericoBruzzone:fix-hoistable-quant-type-segfault

Conversation

@FedericoBruzzone

Copy link
Copy Markdown
Member

HoistIntoGlobalsPass's HoistableTensorTypeInterface unconditionally called getIntOrFloatBitWidth() on a tensor's element type to decide whether it is hoistable, assuming it is always a plain int/float. A !quant.uniform<...> element type is neither, so getIntOrFloatBitWidth() crashes instead of returning a sane answer.

isHoistableType/isHoistableLeafType, with this PR, check that the element type is actually an int/float
before computing its bit width via a new helper hasComputableBitWidth, and conservatively treat anything else as
non-hoistable.

Additonally, quant.uniform types leak into the pipeline because quant is a transitive type dependency of TOSA, not because we have any lowering support for quant.qcast/quant.dcast/quant.scast AFAIK. TOSA's own conversion to linalg/arith is expected to fully resolve these before Flow. VerifyInputLegalityPass already enforces that for those some dialects, quant was simply missing from the list, so IR where these ops survive past GlobalOptimization would segfault later.

Fixes #24814

@AGindinson

Copy link
Copy Markdown
Contributor

Thanks @FedericoBruzzone, I'll give this a proper look tomorrow! Reminded me of my stale PR #22920 which was aiming to address another (narrower?) case, and ultimately I haven't found a good direction upon an apt review comment from Mahesh.

@FedericoBruzzone

FedericoBruzzone commented Aug 18, 2026

Copy link
Copy Markdown
Member Author

Hi @AGindinson! As always, thank you so much. There's no rush 🫶

Tomorrow or later, I'll take a look at your PR to get an idea of what it's about. Sorry, but I didn't have a chance to do that before sending this (I didn't know it existed).

EDIT: Unfortunately, at first glance, I don't think this PR will help #22920. This PR aims to maintain a conservative approach when working with statically unknown size types (i.e., we consider only int and float).

@FedericoBruzzone

Copy link
Copy Markdown
Member Author

Are CI's failures related to this PR? 🤔

@AGindinson

Copy link
Copy Markdown
Contributor

@FedericoBruzzone Not sure what the Bazel issue is about, but doesn't seem to be the case on other PRs/on main. Could you maybe rebase?

Signed-off-by: Federico Bruzzone <federico.bruzzone.i@gmail.com>
@FedericoBruzzone
FedericoBruzzone force-pushed the fix-hoistable-quant-type-segfault branch from 1de98cd to 0902d8f Compare August 20, 2026 13:20
Signed-off-by: Federico Bruzzone <federico.bruzzone.i@gmail.com>
@FedericoBruzzone
FedericoBruzzone force-pushed the fix-hoistable-quant-type-segfault branch from 0902d8f to c6952c1 Compare August 27, 2026 15:05
Signed-off-by: Federico Bruzzone <federico.bruzzone.i@gmail.com>
@FedericoBruzzone
FedericoBruzzone force-pushed the fix-hoistable-quant-type-segfault branch from 488f6bb to 363a085 Compare August 27, 2026 15:32
@FedericoBruzzone

Copy link
Copy Markdown
Member Author

@AGindinson, thanks for checking it out!
I think I fixed the problem in the latest commit :'D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Quant] HoistIntoGlobalsPass segfaults on unlowered quant.uniform types

2 participants