Skip to content

Conversation

@ndossche
Copy link
Contributor

Guard codegen relies on inverting the condition in
ir_emit_guard_cmp_fp. However, for floating point this results in
different behaviour w.r.t. NAN.

For example, if we have GUARD(_, LT(_, _), _) then we should only
continue executing code if LT(_, _) is satisfied.
Inverting the condition and branch targets makes this GE(_, _), but
NANs don't trigger the GE(_, _) condition, resulting in continuing
executing the code if a NAN was present.

To solve this: track whether the condition was inverted and
conditionally generate jumps based on the parity flag.
Because of this change, the "swap operands to avoid P flag check"
optimization also is affected, so fix this as well.

Related to php/php-src#20880

Guard codegen relies on inverting the condition in
`ir_emit_guard_cmp_fp`. However, for floating point this results in
different behaviour w.r.t. NAN.

For example, if we have `GUARD(_, LT(_, _), _)` then we should only
continue executing code if `LT(_, _)` is satisfied.
Inverting the condition and branch targets makes this `GE(_, _)`, but
NANs don't trigger the `GE(_, _)` condition, resulting in continuing
executing the code if a NAN was present.

To solve this: track whether the condition was inverted and
conditionally generate jumps based on the parity flag.
Because of this change, the "swap operands to avoid P flag check"
optimization also is affected, so fix this as well.
@ndossche ndossche marked this pull request as ready for review January 10, 2026 14:07
@ndossche
Copy link
Contributor Author

MacOS fails because of different test output: the decompiler outputs an address instead of the "exit" name. I'm not sure how to fix this. Code itself seems right.

@sanmai
Copy link

sanmai commented Jan 10, 2026

@ndossche ndossche#1 fixes it following the pattern from argval_002.irt

@dstogov
Copy link
Owner

dstogov commented Jan 12, 2026

Thanks for looking into the problem.
However, I made a more general fix. See #123

@ndossche
Copy link
Contributor Author

Okay I see. Thanks.

@ndossche ndossche closed this Jan 12, 2026
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.

3 participants