Skip to content

[InstCombine] Fix 0.0 / x -> 0 folds when the divisor may be zero - #156

Merged
alexey-milovidov merged 1 commit into
ClickHouse/release-23.xfrom
fix-fdiv-zero-fold-23.x
Nov 16, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse/release-23.xfrom
fix-fdiv-zero-fold-23.x

Conversation

@alexey-milovidov

Copy link
Copy Markdown
Member

Cherry-pick of upstream llvm#202482 (commit bcb4e7d061ac), which is not in upstream release/23.x.

SimplifyDemandedUseFPClass folded +0.0 / x to copysign(0.0, x) when x is known to be not NaN, but 0 / 0 is NaN. The fold was added in llvm#175946 (LLVM 23 cycle).

This miscompiles ClickHouse JIT-compiled expressions since the update to LLVM 23 (ClickHouse/ClickHouse#117346): SELECT c0 * (0 / c0) FROM values('c0 Int32', 0) SETTINGS compile_expressions = 1, min_count_to_compile_expression = 0 returns 0 instead of nan, because sitofp is never NaN but can be zero. Found by SQLancer (Parallelism oracle) on ClickHouse master. Verified with the ClickHouse build: with this patch the expression returns nan.

🤖 Generated with Claude Code

…vm#202482)

SimplifyDemandedUseFPClass folded 0/x to a signed zero, guarded only on
the divisor being non-NaN. But when x==0, the result is is NaN, not 0!

Require the divisor to be never (logical) zero, unless a NaN result
isn't demanded.

(cherry picked from commit bcb4e7d)
@cla-assistant

cla-assistant Bot commented Nov 16, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@alexey-milovidov alexey-milovidov self-assigned this Nov 16, 2026
@alexey-milovidov
alexey-milovidov merged commit 2add44a into ClickHouse/release-23.x Nov 16, 2026
7 of 8 checks passed
alexey-milovidov added a commit to ClickHouse/ClickHouse that referenced this pull request Nov 16, 2026
… fix for illumos

Advances the submodule to the tip of `ClickHouse/release-23.x`, which
initializes the secret with `getentropy` on non-Linux platforms
(ClickHouse/llvm-project#155, ClickHouse/llvm-project#157)
and includes an `InstCombine` fix (ClickHouse/llvm-project#156).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-ClickHouse__ClickHouse that referenced this pull request Nov 17, 2026
LLVM 23 `SimplifyDemandedUseFPClass` folded `+0.0 / x` to `copysign(0.0, x)`
when `x` is known to be not NaN, ignoring that `0 / 0` is NaN. JIT-compiled
expressions like `c0 * (0 / c0)` over an integer column returned `0` instead of
`nan` for `c0 = 0` since the update to LLVM 23. Cherry-pick the upstream fix
llvm/llvm-project#202482 into the fork:
ClickHouse/llvm-project#156

Found by SQLancer (`Parallelism` oracle) on master:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=fdc4389b67de6aa94e602b884e1c403306184af7&name_0=NightlySQLancer&name_1=SQLancer%20%28arm_release%29

Caused by: ClickHouse#117346

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants