[fix](be) Preserve floating point values in CASE branch selection - #67896
Open
HappenLee wants to merge 1 commit into
Open
[fix](be) Preserve floating point values in CASE branch selection#67896HappenLee wants to merge 1 commit into
HappenLee wants to merge 1 commit into
Conversation
### What problem does this PR solve? Issue Number: N/A Related PR: N/A Problem Summary: Non-nullable FLOAT/DOUBLE CASE assembles results by multiplying branch values by zero or one and adding them to a zero-initialized result. An unselected Infinity or NaN therefore contaminates a finite selected result, and a selected negative zero loses its sign. For example, a three-row CASE selecting 1, an overflowing multiplication, and 2 returns NaN, Infinity, NaN instead. Use conditional stores for floating point columns so that only selected values are copied. This preserves their bits and lets Clang generate AVX2 masked loads/stores; a ternary source/result load can inhibit vectorization. Keep the other type paths unchanged. Add bitwise unit tests, SQL regression coverage and a benchmark that invokes 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: 12 ASAN unit tests; test_case_float_nonfinite and test_short_circuit_evaluation regression suites passed. The original code fails all 12 new unit tests and the new SQL regression. Golden output was generated and verified through short-circuit evaluation using the runner. ASAN BE build, clang-format 16, header hygiene and clang-tidy passed. RELEASE AVX2 benchmarks on Xeon Platinum 8457C cover 42 scenarios using identical input, fixed CPU and repeated before/after/after/before runs; median CPU time decreased by 5% to 39%. Inspected all four floating point and index-width specializations in the linked binaries for masked SIMD. - Behavior changed: Yes, return only the selected floating point branch value. - Does this need documentation: No
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, and2over three rows returnsNaN, Infinity, NaNinstead of1, 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 * Infinityand0 * NaNequal 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
Validation:
test_case_float_nonfiniteandtest_short_circuit_evaluationpass. The original implementation fails the new SQL regression. Golden output was generated and independently verified through short-circuit evaluation using the regression runner.-O3 -msse4.2 -mavx2on 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.vmaskmovps/pd, replacing floating point multiply/add instructions without fast-math.Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)