JIT: fix profile likelihood and overflow UB in optimizebools#128951
JIT: fix profile likelihood and overflow UB in optimizebools#128951AndyAyersMS wants to merge 1 commit into
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
Pull request overview
This PR tightens correctness and safety in the JIT boolean/range optimization code paths by (1) fixing a likelihood computation used during boolean-block folding and (2) removing undefined behavior risk in range-intersection normalization, plus a small comment cleanup.
Changes:
- Fixes the
!sameTargetedge likelihood computation inOptBoolsDsc::optOptimizeBoolsUpdateTrees()to reflect the actual probability path to B2’s true target. - Hardens
GetIntersectionby preventing signed overflow UB when normalizingX > SSIZE_T_MAX(and makes normalization explicitly fail-fast). - Updates a stale comment in
optIsBoolCompthat referenced a nonexistentGTF_BOOLEANflag.
Fix two issues in optOptimizeBoolsUpdateTrees and GetIntersection: 1. The !sameTarget branch likelihood formula was computing (1-p1) + p1*p2_false = 1 - p1*p2_true, but the correct probability of reaching B2's true target is (1-p1) * p2_true (B1 falls through, then B2 jumps). Also fixed the misleading comment. 2. The normalize lambda in GetIntersection could overflow when cns == SSIZE_T_MAX and cmp == GT_GT (signed overflow is UB in C++). Added an explicit guard and made the lambda return bool to signal failure. 3. Updated a stale comment referencing the nonexistent GTF_BOOLEAN flag in optIsBoolComp. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
4ab214c to
ad9e21f
Compare
|
Note This review was generated by Copilot. 🤖 Copilot Code Review — PR #128951Holistic AssessmentMotivation: All three fixes address real bugs: a mathematically incorrect profile likelihood formula, potential signed overflow UB in C++, and a misleading stale comment. These are legitimate correctness issues. Approach: The fixes are minimal, surgical, and correct. Each change addresses exactly the identified problem without unnecessary restructuring. Summary: ✅ LGTM. The three changes are independently correct. The likelihood formula fix properly computes P(B1 falls through) × P(B2 jumps) = (1-p1) × p2_true. The overflow guard handles the SSIZE_T_MAX edge case cleanly. The comment and redundant check cleanup are straightforward. Detailed Findings✅ Correctness — Likelihood formula fix (line 1253)The old formula ✅ Correctness — Overflow guard in GetIntersection (line 455)When ✅ Cleanup — Redundant OperIs check removed (line 1423)
💡 Minor — Consider SSIZE_T_MIN guard for GT_LTThe comment on line 465 explains why GT_LT subtraction is safe (cns is non-negative). This is correct. However, if the non-negative check at line 444 were ever relaxed in the future, the GT_LT path would need a similar guard for
|
Fix two issues in optOptimizeBoolsUpdateTrees and GetIntersection:
The !sameTarget branch likelihood formula was computing (1-p1) + p1p2_false = 1 - p1p2_true, but the correct probability of reaching B2's true target is (1-p1) * p2_true (B1 falls through, then B2 jumps). Also fixed the misleading comment.
The normalize lambda in GetIntersection could overflow when cns == SSIZE_T_MAX and cmp == GT_GT (signed overflow is UB in C++). Added an explicit guard and made the lambda return bool to signal failure.
Updated a stale comment referencing the nonexistent GTF_BOOLEAN flag in optIsBoolComp.