[all-commits] [llvm/llvm-project] 6311e3: [ValueTracking] ComputeNumSignBitsImpl - add basic...

Narayan via All-commits all-commits at lists.llvm.org
Thu Mar 6 00:30:58 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 6311e3fcc8539cf0f474b28f82a465e83013a792
      https://github.com/llvm/llvm-project/commit/6311e3fcc8539cf0f474b28f82a465e83013a792
  Author: Narayan <32898329+vortex73 at users.noreply.github.com>
  Date:   2025-03-06 (Thu, 06 Mar 2025)

  Changed paths:
    M llvm/lib/Analysis/ValueTracking.cpp
    A llvm/test/Transforms/InstCombine/compute-sign-bits-bitcast.ll

  Log Message:
  -----------
  [ValueTracking] ComputeNumSignBitsImpl - add basic handling of BITCAST nodes (#127218)

When a wider scalar/vector type containing all sign bits is bitcast to a
narrower vector type, we can deduce that the resulting narrow elements
will also be all sign bits. This matches existing behavior in
SelectionDAG and helps optimize cases involving SSE intrinsics where
sign-extended values are bitcast between different vector types.

The current implementation fails to recognize that an arithmetic right
shift is redundant when applied to elements that are already known to be
all sign bits. This PR improves ComputeNumSignBitsImpl to track this
information through bitcasts, enabling the optimization of such cases.

```
%ext = sext <1 x i1> %cmp to <1 x i8>
%sub = bitcast <1 x i8> %ext to <4 x i2>
%sra = ashr <4 x i2> %sub, <i2 1, i2 1, i2 1, i2 1>
; Can be simplified to just:
%sub = bitcast <1 x i8> %ext to <4 x i2>
```

Closes #87624



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