-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix Sema unreachable when shfting by vector containing undef elems #24396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
I cannot reproduce the CI failure locally from a M1 MacBook Pro using
I'm using qemu 10.0.2 from homebrew, could this be something that can only be reprod with ziglang/static-qemu? EDIT: I was able to retrieve a loongarch64 coredump by running static-qemu qemu-loongarch64 on utm debian 11 |
It is quite possible that this failure is not actually your fault. Did you find anything interesting in the coredump? |
Managed to repro that failure locally, will investigate. |
Going with #24407 for now to get CI stable. |
Thanks for the help! I haven't had time to look into the coredump yet but I'll let you know if I find anything. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch. I'm not entirely sure about these changes. For one thing, the use of bit_count
in place of undefined
at runtime isn't great -- the backend would like to know about undefined
values so it can use them to optimize!
But more importantly, I actually suspect that shifting with an undefined
operand should be a compile error. Our usual rule (as of #23177) is that if an operator can trigger IB, then passing undefined
-- to any operand -- does trigger IB. Since e.g. my_u31 << runtime_31
can indeed trigger IB, it seems to me that it logically follows that shifting should follow the "undefined
causes IB" rule. Of course, my_u32 << x
can't trigger IB, but I think we should avoid type-dependence for IB rules. #3806 would theoretically eliminate the IB, but my gut still tells me that this should be IB.
If it is IB, then this gets much simpler: it's just a compile error for either operand to be undefined
or have undefined
as a vector element. I think it would be reasonable for now to implement that, because I believe it is more in line with the direction we're taking.
(Of course, if you don't want to make that change, feel free to just close this PR, and we'll get to this at some point!)
Thanks for the feedback, makes sense in light of #23177! |
ab010b4
to
d54fbb4
Compare
Yep, I agree that |
Added additional checks for undefined values and vectors containing undefined elements in `zirShl` and `zirShr`. This also fixes a bug when shifting by a partially undefined vector that reached unreachable in `compareHetero` and `getUnsignedInt`. This patch pretends that `Value.isUndefDeep()` is already implemented (TBC).
d54fbb4
to
678fe03
Compare
I noticed that quite a lot of functions in |
Now correctly returns `true` for aggregates containing only undefined elements, undefined unions without a (safety) tag.
678fe03
to
c7c9b92
Compare
Ah, so, the doc comment on Of course, if you'd like to try your hand at implementing that, by all means feel free! However, the InternPool might be a little tricky if you've not worked in that code before. Although, thinking about it, it might be a better idea to do it in a layer outside of the |
Closes #24392
I added some missing checks for undef values before using
compareHetero
andgetUnsignedInt
to avoid hitting an unreachable prong.This also enables a small AIR optimization basically for free that replaces a vec that only contains undef elems with a single undef value and returns early from
zirShl
/zirShr
, skipping some unnecessary logic and emitting a shift instruction:old AIR
new AIR
old LLVM IR
ReleaseFast:
new LLVM IR
ReleaseFast: