[all-commits] [llvm/llvm-project] df633b: [InstCombine] Fold icmp on frexp exponent to fcmp ...
FathimaHaris via All-commits
all-commits at lists.llvm.org
Sat Aug 8 11:16:47 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: df633b22c76997a9b189d02995528610f0858293
https://github.com/llvm/llvm-project/commit/df633b22c76997a9b189d02995528610f0858293
Author: FathimaHaris <156105585+FathimaHaris at users.noreply.github.com>
Date: 2026-08-09 (Sun, 09 Aug 2026)
Changed paths:
M llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
M llvm/test/Transforms/InstCombine/frexp-implied-exponent-range-dominating-conditions.ll
M llvm/test/Transforms/InstCombine/known-range-frexp-exp.ll
Log Message:
-----------
[InstCombine] Fold icmp on frexp exponent to fcmp on fabs(x) (#210711)
Recognize signed icmp predicates comparing extractvalue(frexp(x), 1)
against an
integer constant and rewrite them as equivalent fcmp comparisons of
fabs(x)
against the corresponding power-of-two threshold.
frexp(x) returns a mantissa in [0.5, 1) and an exponent E such that
2^(E-1) <= | x | < 2^E.
When code only checks that exponent against a constant, the comparison
can be rewritten directly in terms of | x |, dropping the need for
frexp's exponent output:
icmp spred i32 (extractvalue (frexp x), 1), C
--> fcmp fpred float (fabs x), 2^ExpVal
Predicate mapping:
- slt --> olt (ExpVal = C-1)
- sgt --> oge (ExpVal = C)
Alive2 Generic proof: https://alive2.llvm.org/ce/z/aqEu4p
Fixes #186554 .
**Test updates**
This patch also updates
frexp-implied-exponent-range-dominating-conditions.ll.
The _nofold tests in this file were originally checking that the
dominating
condition alone could not fold the comparison to a constant. After this
patch,
the remaining frexp exponent comparison is itself recognized by the new
fold,
so these tests now simplify to fabs/fcmp.
At the -passes=instcombine pass , the transformed IR temporarily
contains two fabs calls (one from the dominating-condition fold and one
introduced by this transform). A later optimization pass in the full -O3
pipeline
removes the duplicate fabs, producing the fully simplified IR.
Alive2 proofs:
- -passes=instcombine : https://alive2.llvm.org/ce/z/ZLHh8V
- Full -O3 pipeline : https://alive2.llvm.org/ce/z/5P3pUC
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list