[llvm] [NVPTX] Set boolean contents to zero-or-one (PR #108969)

Justin Fargnoli via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 17 11:01:40 PDT 2024


justinfargnoli wrote:

Notes: 

> Note that this field is a property of SelectionDAG rather than one of the ISA. The previous value wasn't incorrect, per se, but since NVPTX uses 1-bit predicate registers, either choice is possible.

This is correct (source: [Section 4.5 "Constants" of PTX ISA](https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#constants)):
> For predicate-type data and instructions, integer constants are allowed and are interpreted as in C, i.e., zero values are False and non-zero values are True.

---

[Compiler Explorer reproducer](https://godbolt.org/z/cKM5csYx4). 

Incorrect transformation occurs during DAG optimization:
```
Initial selection DAG: %bb.0 'sext_setcc:entry'
SelectionDAG has 14 nodes:
  t0: ch,glue = EntryToken
              t4: v1i32,ch = load<(dereferenceable invariant load (s32) from `ptr addrspace(101) null`, addrspace 101)> t0, TargetExternalSymbol:i32'sext_setcc_param_0', undef:i32
            t5: i32 = extract_vector_elt t4, Constant:i32<0>
          t6: v2i16,ch = load<(load (s32) from %ir.p)> t0, t5, undef:i32
          t8: v2i16 = BUILD_VECTOR Constant:i16<0>, Constant:i16<0>
        t10: v2i1 = setcc t6, t8, seteq:ch
      t11: v2i16 = sign_extend t10
    t12: ch = NVPTXISD::StoreRetval<(store (s32), align 1)> t0, Constant:i32<0>, t11
  t13: ch = NVPTXISD::RET_GLUE t12



Optimized lowered selection DAG: %bb.0 'sext_setcc:entry'
SelectionDAG has 13 nodes:
  t0: ch,glue = EntryToken
            t4: v1i32,ch = load<(dereferenceable invariant load (s32) from `ptr addrspace(101) null`, addrspace 101)> t0, TargetExternalSymbol:i32'sext_setcc_param_0', undef:i32
          t5: i32 = extract_vector_elt t4, Constant:i32<0>
        t6: v2i16,ch = load<(load (s32) from %ir.p)> t0, t5, undef:i32
        t8: v2i16 = BUILD_VECTOR Constant:i16<0>, Constant:i16<0>
      t14: v2i16 = setcc t6, t8, seteq:ch
    t12: ch = NVPTXISD::StoreRetval<(store (s32), align 1)> t0, Constant:i32<0>, t14
  t13: ch = NVPTXISD::RET_GLUE t12
```

https://github.com/llvm/llvm-project/pull/108969


More information about the llvm-commits mailing list