[all-commits] [llvm/llvm-project] 50d10b: [Clang] Add __builtin_assume_dereferenceable to en...

Florian Hahn via All-commits all-commits at lists.llvm.org
Fri Feb 14 03:44:41 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 50d10b5c1c26c12570d3d31ef24b1a880fd23e26
      https://github.com/llvm/llvm-project/commit/50d10b5c1c26c12570d3d31ef24b1a880fd23e26
  Author: Florian Hahn <flo at fhahn.com>
  Date:   2025-02-14 (Fri, 14 Feb 2025)

  Changed paths:
    M clang/docs/LanguageExtensions.rst
    M clang/include/clang/Basic/Builtins.td
    M clang/lib/CodeGen/CGBuiltin.cpp
    A clang/test/CodeGen/builtin-assume-dereferenceable.c
    A clang/test/SemaCXX/builtin-assume-dereferenceable.cpp
    M llvm/include/llvm/IR/IRBuilder.h
    M llvm/lib/IR/IRBuilder.cpp

  Log Message:
  -----------
  [Clang] Add __builtin_assume_dereferenceable to encode deref assumption. (#121789)

This patch adds a new __builtin_assume_dereferenceable to encode
dereferenceability of a pointer using llvm.assume with an operand
bundle.

For now the builtin only accepts constant sizes, I am planning to drop
this restriction in a follow-up change.

This can be used to better optimize cases where a pointer is known to be
dereferenceable, e.g. unconditionally loading from p2 when vectorizing
the loop.

    int *get_ptr();

    void foo(int* src, int x) {
      int *p2 = get_ptr();
      __builtin_assume_aligned(p2, 4);
      __builtin_assume_dereferenceable(p2, 4000);
      for (unsigned I = 0; I != 1000; ++I) {
        int x = src[I];
        if (x == 0)
          x = p2[I];
	 src[I] = x;
      }
    }


PR: https://github.com/llvm/llvm-project/pull/121789



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