[all-commits] [llvm/llvm-project] 9211e6: [NVVMReflect] Force dead branch elimination in NVV...

Joseph Huber via All-commits all-commits at lists.llvm.org
Thu Feb 8 15:16:43 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9211e67da36782db44a46ccb9ac06734ccf2570f
      https://github.com/llvm/llvm-project/commit/9211e67da36782db44a46ccb9ac06734ccf2570f
  Author: Joseph Huber <huberjn at outlook.com>
  Date:   2024-02-08 (Thu, 08 Feb 2024)

  Changed paths:
    M llvm/docs/NVPTXUsage.rst
    M llvm/lib/Target/NVPTX/NVVMReflect.cpp
    A llvm/test/CodeGen/NVPTX/nvvm-reflect-arch-O0.ll
    M llvm/test/CodeGen/NVPTX/nvvm-reflect-arch.ll

  Log Message:
  -----------
  [NVVMReflect] Force dead branch elimination in NVVMReflect (#81189)

Summary:
The `__nvvm_reflect` function is used to guard invalid code that varies
between architectures. One problem with this feature is that if it is
used without optimizations, it will leave invalid code in the module
that will then make it to the backend. The `__nvvm_reflect` pass is
already mandatory, so it should do some trivial branch removal to ensure
that constants are handled correctly. This dead branch elimination only
works in the trivial case of a compare on a branch and does not touch
any conditionals that were not realted to the `__nvvm_reflect` call in
order to preserve `O0` semantics as much as possible. This should allow
the following to work on NVPTX targets

```c
int foo() {
  if (__nvvm_reflect("__CUDA_ARCH") >= 700)
    asm("valid;\n");
}
```




More information about the All-commits mailing list