[all-commits] [llvm/llvm-project] e5851a: [NVPTX] Fix fptosi/fptoui to i1. (#200718)

Justin Lebar via All-commits all-commits at lists.llvm.org
Mon Jun 1 11:29:02 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e5851a8f307a8e59742c5ab8fed7abdbe3f9cf21
      https://github.com/llvm/llvm-project/commit/e5851a8f307a8e59742c5ab8fed7abdbe3f9cf21
  Author: Justin Lebar <justin.lebar at gmail.com>
  Date:   2026-06-01 (Mon, 01 Jun 2026)

  Changed paths:
    M llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
    M llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
    M llvm/test/CodeGen/NVPTX/convert-fp.ll

  Log Message:
  -----------
  [NVPTX] Fix fptosi/fptoui to i1. (#200718)

The langref says:

> The 'fptosi' instruction converts its floating-point operand into the
> nearest (rounding towards zero) signed integer value. If the value
> cannot fit in ty2, the result is a poison value.

Previously `fptosi to i1` and `fptoui to i1` were lowered as `x == 0.0`,
which is clearly incorrect.

Because the conversion truncates toward zero, the only results that are
not poison are:

 - 0 and -1 for the signed case, and
 - 0 and 1 for the unsigned case.

So the i1 result is fully determined by a single fp compare:

 - `fptosi x to i1`  ==  `x <= -1.0`
 - `fptoui x to i1`  ==  `x >= 1.0`

with any value being acceptable for the poison (out-of-range) inputs.



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