[all-commits] [llvm/llvm-project] d775fc: [InstCombine] Generate better code for std::bit_fl...

kazutakahirata via All-commits all-commits at lists.llvm.org
Sat Apr 15 11:32:54 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d775fc390d3c78cc81872e276c4b1314f19af577
      https://github.com/llvm/llvm-project/commit/d775fc390d3c78cc81872e276c4b1314f19af577
  Author: Kazu Hirata <kazu at google.com>
  Date:   2023-04-15 (Sat, 15 Apr 2023)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
    M llvm/test/Transforms/InstCombine/bit_floor.ll

  Log Message:
  -----------
  [InstCombine] Generate better code for std::bit_floor from libstdc++

Without this patch, std::bit_floor<uint32_t> in libstdc++ is compiled
as:

  %eq0 = icmp eq i32 %x, 0
  %lshr = lshr i32 %x, 1
  %ctlz = tail call i32 @llvm.ctlz.i32(i32 %lshr, i1 false)
  %sub = sub i32 32, %ctlz
  %shl = shl i32 1, %sub
  %sel = select i1 %eq0, i32 0, i32 %shl

With this patch:

  %eq0 = icmp eq i32 %x, 0
  %ctlz = call i32 @llvm.ctlz.i32(i32 %x, i1 false)
  %lshr = lshr i32 -2147483648, %1
  %sel = select i1 %eq0, i32 0, i32 %lshr

This patch recognizes the specific pattern emitted for std::bit_floor
in libstdc++.

https://alive2.llvm.org/ce/z/piMdFX

This patch fixes:

https://github.com/llvm/llvm-project/issues/61183

Differential Revision: https://reviews.llvm.org/D145890




More information about the All-commits mailing list