Issue 87624
Summary [ValueTracking] ComputeNumSignBitsImpl - add basic handling of BITCAST nodes
Labels good first issue, llvm:instcombine, llvm:support
Assignees
Reporter RKSimon
    At the very least ComputeNumSignBitsImpl should be able to report that if we bitcast from a wider scalar/vector type to a narrow vector element type, and the original wide type was all sign bits then the destination narrow type elements will be all sign bits as well.

SelectionDAG already does this (and quite a bit more, but for the "fast case" would be enough): https://github.com/llvm/llvm-project/blob/5ad320abe36357e3290007d3ab353e8637f33720/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp#L4425-L4469

Encountered while fighting bitcasts between SSE intrinsics.

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

```
----------------------------------------
define <4 x i2> @src(<1 x i8> %a0, <1 x i8> %a1) {
#0:
  %cmp = icmp sgt <1 x i8> %a0, %a1
  %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, { 1, 1, 1, 1 }
 ret <4 x i2> %sra
}
=>
define <4 x i2> @tgt(<1 x i8> %a0, <1 x i8> %a1) {
#0:
  %cmp = icmp sgt <1 x i8> %a0, %a1
  %ext = sext <1 x i1> %cmp to <1 x i8>
  %sub = bitcast <1 x i8> %ext to <4 x i2>
  ret <4 x i2> %sub
}
Transformation seems to be correct!
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to