[all-commits] [llvm/llvm-project] ffabcb: [NVVMReflect][Reland] Force dead branch eliminatio...

Joseph Huber via All-commits all-commits at lists.llvm.org
Thu Feb 8 18:10:00 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ffabcbcf8f9fc7ef5fd29e2a711f95aba0ef7808
      https://github.com/llvm/llvm-project/commit/ffabcbcf8f9fc7ef5fd29e2a711f95aba0ef7808
  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][Reland] 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");
}
```

Relanding after fixing a bug.




More information about the All-commits mailing list