llvm / llvm/llvm-project

[LLVM][IR] LLVM fails to optimize saturated float conversion expressions down to @llvm.fptosi.sat/@llvm.fptoui.sat calls

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

Description

Here is a link to an LLVM IR snippet showing LLVM failing to optimize saturated float conversion expressions to @llvm.fptosi.sat/@llvm.fptoui.sat:
https://alive2.llvm.org/ce/z/id6gSA

Here are the equivalent C expressions that LLVM fails to optimize to @llvm.fptosi.sat/@llvm.fptoui.sat:
- F32 to I32: `(x >= 2147483648.0f) ? INT32_MAX : ((x >= -2147483648.0f) ? (int32_t)x : ((x == x) ? INT32_MIN : 0))`
- F32 to U32: `(x >= 4294967296.0f) ? UINT32_MAX : ((x >= 0.0f) ? (uint32_t)x : 0)`
- F64 to I32: `(x > 2147483647.0) ? INT32_MAX : ((x >= -2147483648.0) ? (int32_t)x : ((x == x) ? INT32_MIN : 0))`
- F64 to U32: `(x > 4294967295.0) ? UINT32_MAX : ((x >= 0.0) ? (uint32_t)x : 0)`

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.