[all-commits] [llvm/llvm-project] c70b9c: [AMDGPU] Fold redundant inf/nan checks into frexp ...

Addmisol via All-commits all-commits at lists.llvm.org
Mon Sep 7 11:37:28 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: c70b9c09f691d93c6e46e2692e15fb439dcb2560
      https://github.com/llvm/llvm-project/commit/c70b9c09f691d93c6e46e2692e15fb439dcb2560
  Author: Addmisol <addmisol9 at gmail.com>
  Date:   2026-09-07 (Mon, 07 Sep 2026)

  Changed paths:
    M llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
    M llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h
    M llvm/lib/Target/AMDGPU/SIISelLowering.cpp
    M llvm/lib/Target/AMDGPU/SIISelLowering.h
    M llvm/test/CodeGen/AMDGPU/frexp-inf-nan-combine.ll

  Log Message:
  -----------
  [AMDGPU] Fold redundant inf/nan checks into frexp instructions (#214936)

Fixes #204204

The AMDGPU "v_frexp_exp" and "v_frexp_mant" instructions return 0 for
inf/nan inputs. This patch adds a DAG combine
("performFrexpSelectCombine") to fold redundant inf/nan checks with
frexp results, eliminating unnecessary compare and select instructions..

### Patterns folded:
  - `select (fcmp uno x, 0), 0, (frexp_exp x)` → `frexp_exp x`
  - `select (fcmp oeq |x|, inf), 0, (frexp_exp x)` → `frexp_exp x`
  - `select (fcmp ueq |x|, inf), 0, (frexp_exp x)` → `frexp_exp x`
  - `select (fcmp ord x, 0), (frexp_exp x), 0` → `frexp_exp x`
  - `select (fcmp one |x|, inf), (frexp_exp x), 0` → `frexp_exp x`
  - `select (is_fpclass x, finite), (frexp_exp x), 0` → `frexp_exp x`
  - Same patterns with `frexp_mant`

The optimization is disabled on SI (Southern Islands) which has
hasFractBug()..

## Test plan

    - [x] Added frexp-inf-nan-combine.ll with comprehensive tests for:
- Targets: GFX9, GFX10, GFX11, GFX950 (optimization applies), SI
(optimization does NOT apply)
    - Types: f32, f64, f16
- Patterns: NaN clamp, inf clamp, inf-or-nan clamp, reversed select,
not-inf check
- Negative tests: different inputs, non-zero constants, unrelated
comparisons

All existing frexp-related AMDGPU tests pass..



cc @arsenm

---------

Signed-off-by: addmisol <addmisol9 at gmail.com>



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