llvm / llvm/llvm-project

Recent regression of sqrt optimization when the argument cannot be negative

Open
#175,166 8 comments 0 reactions 0 assignees View on GitHub
llvm:instcombine missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

With LLVM 21, and until a few days ago with trunk, the following code would be optimized to not have a branch to a sqrt library call, as it is impossible for the square of a number to be invalid input for sqrt, therefore having to potentially set errno is not required.
The responsible transformation used to happen in AggressiveInstCombinePass.
See: https://godbolt.org/z/bqWedbKfd
But in the last few days something regressed this and AggressiveInstCombinePass misses this optimization.
Related but distinct issue: #174813

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.