[all-commits] [llvm/llvm-project] 7298ae: [clang][CodeGen] Fix in codegen for __builtin_popc...

Björn Pettersson via All-commits all-commits at lists.llvm.org
Thu May 2 13:50:00 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 7298ae3b6d97777443aa89e38ab34b15482abfb3
      https://github.com/llvm/llvm-project/commit/7298ae3b6d97777443aa89e38ab34b15482abfb3
  Author: Björn Pettersson <bjorn.a.pettersson at ericsson.com>
  Date:   2024-05-02 (Thu, 02 May 2024)

  Changed paths:
    M clang/lib/CodeGen/CGBuiltin.cpp
    A clang/test/CodeGen/builtins-bitint.c
    M clang/test/CodeGen/builtins.c

  Log Message:
  -----------
  [clang][CodeGen] Fix in codegen for __builtin_popcountg/ctzg/clzg (#90845)

Make sure that the result from the popcnt/ctlz/cttz intrinsics is
unsigned casted to int, rather than casted as a signed value, when
expanding the __builtin_popcountg/__builtin_ctzg/__builtin_clzg
builtins.

An example would be
  unsigned _BitInt(1) x = ...;
  int y = __builtin_popcountg(x);
which previously was incorrectly expanded to
  %1 = call i1 @llvm.ctpop.i1(i1 %0)
  %cast = sext i1 %1 to i32

Since the input type is generic for those "g" versions of the builtins
the intrinsic call may return a value for which the sign bit is set
(that could typically for BitInt of size 1 and 2). So we need to emit a
zext rather than a sext to avoid negative results.



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