HappenLee opened a new pull request, #67896:
URL: https://github.com/apache/doris/pull/67896

   ### What problem does this PR solve?
   
   Issue Number: N/A
   
   Related PR: N/A
   
   Problem Summary: A non-nullable FLOAT/DOUBLE CASE can return NaN for a 
finite selected branch when an unselected branch contains Infinity or NaN. For 
example, with ordinary CASE evaluation, selecting `1`, an overflowing 
multiplication, and `2` over three rows returns `NaN, Infinity, NaN` instead of 
`1, Infinity, 2`. The same result assembly also loses the sign of selected 
negative zero.
   
   The result assembly multiplies each branch value by a zero/one mask and adds 
it to the result. IEEE-754 arithmetic makes `0 * Infinity` and `0 * NaN` equal 
NaN. Replace this floating point path with conditional stores so that selected 
values are copied without arithmetic. This form generates AVX2 masked 
loads/stores; a ternary assignment can instead become a conditional pointer 
load that inhibits vectorization.
   
   Add bitwise unit tests, SQL regression tests and a benchmark that directly 
calls the production result assembly function.
   
   ### Release note
   
   Fix incorrect FLOAT/DOUBLE CASE results caused by unselected non-finite 
branch values, and preserve selected negative zero.
   
   ### Check List (For Author)
   
   - Test
       - [x] Regression test
       - [x] Unit Test
       - [x] Manual test (details below)
       - [ ] No need to test or manual test.
   
     Validation:
     - All 12 new unit tests fail on the original implementation and pass with 
ASAN after the fix. Coverage includes FLOAT/DOUBLE, uint8_t/uint16_t indices, 
constant columns, non-finite values, signed zero, subnormal values, vector 
tails, and 255/257 branches.
     - `test_case_float_nonfinite` and `test_short_circuit_evaluation` pass. 
The original implementation fails the new SQL regression. Golden output was 
generated and independently verified through short-circuit evaluation using the 
regression runner.
     - ASAN BE build, clang-format 16, header hygiene, and clang-tidy checks 
pass.
     - RELEASE benchmarks built with Clang 21.1.8 and `-O3 -msse4.2 -mavx2` on 
Xeon Platinum 8457C cover 42 scenarios. With identical input, a fixed CPU, five 
repetitions per run and before/after/after/before ordering, median CPU time 
decreases by approximately 5%–39% (18.5% geometric mean reduction). This 
measures the result assembly function on this AVX2 machine, including result 
allocation.
     - Disassembly of all four floating point/index-width specializations in 
the linked binaries confirms `vmaskmovps/pd`, replacing floating point 
multiply/add instructions without fast-math.
   
   - Behavior changed:
       - [ ] No.
       - [x] Yes. Return the selected floating point value without 
contamination from other branches or loss of negative zero.
   
   - Does this need documentation?
       - [x] No.
       - [ ] Yes.
   
   ### Check List (For Reviewer who merge this PR)
   
   - [ ] Confirm the release note
   - [ ] Confirm test cases
   - [ ] Confirm document
   - [ ] Add branch pick label
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to