[llvm] [X86][GlobalIsel] G_BITCAST support (PR #144473)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 1 02:13:48 PDT 2025


mahesh-attarde wrote:

> > > @mahesh-attarde could you please elaborate why this change is needed because the tests pass without this PR: https://godbolt.org/z/EEzP4nn4n
> > > There is a problem with double conversions in `test2` on `i686` but it is all over there.
> > 
> > 
> > While doing FP class test we need to convert F32 to I32 and F64 to I64 and create sequence of bitwise ops.
> 
> Is there a test in IR or GIR that shows the problem? Because current tests only show that this PR workarounds an issue with doubles on `i686`.
For IR , We have check for INF.
```
define i1 @foo_f(float %x) {
   %a0 = tail call i1 @llvm.is.fpclass.f32(float %x, i32 516)  ; "snan"
   ret i1 %a0
}
```
GIR
```
bb.1 (%ir-block.0):
  liveins: $xmm0
  %0:_(s32) = COPY $xmm0
  %3:_(s32) = G_BITCAST %0:_(s32)
  %4:_(s32) = G_CONSTANT i32 2147483647
  %6:_(s32) = G_CONSTANT i32 2139095040
  %10:_(s32) = G_AND %3:_, %4:_
  %13:_(s8) = G_ICMP intpred(eq), %10:_(s32), %6:_
  %12:_(s1) = G_TRUNC %13:_(s8)
  %1:_(s1) = COPY %12:_(s1)
  %2:_(s8) = G_ANYEXT %1:_(s1)
  $al = COPY %2:_(s8)
  RET 0, implicit $al

```

We halt at legalization 
```
LLVM ERROR: unable to legalize instruction: %3:_(s32) = G_BITCAST %0:_(s32)
```
To rectify this I legalized BITCAST with  COPY, patch addressed it.

https://github.com/llvm/llvm-project/pull/144473


More information about the llvm-commits mailing list