Issue 171856
Summary [GlobalISel][Combiner] Failure when constant folding FCmp
Labels llvm:globalisel, llvm:optimizations
Assignees
Reporter jfuentes
    Given the input IR 

```llvm
 define void @vadd(ptr addrspace(1) %a) {
  %1 = call double @llvm.fabs.f64(double 0x5d3b0b8040df92c9)
  %2 = bitcast double %1 to i64
  %3 = trunc i64 %2 to i32
  %4 = bitcast i32 %3 to float
  %5 = fcmp oge float %4, 0x3E6BBDE420000000
  %6 = select i1 %5, i32 13, i32 44
 store i32 %6, ptr addrspace(1) %a
  ret void
}
```

Compiling with
```
llc -march=amdgcn -global-isel=1 -print-after-all -start-after=callbrprepare test.ll
```

Whe get the following MIR before pre-legalizer combiner:

```
bb.1 (%ir-block.0):
  liveins: $vgpr0, $vgpr1
  %9:_(s32) = COPY $vgpr0
  %10:_(s32) = COPY $vgpr1
  %0:_(p1) = G_MERGE_VALUES %9:_(s32), %10:_(s32)
  %11:_(s64) = G_FCONSTANT double 0x5D3B0B8040DF92C9
  %14:_(s32) = G_FCONSTANT float 0x3E6BBDE420000000
 %17:_(s32) = G_CONSTANT i32 13
  %18:_(s32) = G_CONSTANT i32 44
 %12:_(s64) = G_FABS %11:_
  %13:_(s32) = G_TRUNC %12:_(s64)
  %15:_(s1) = G_FCMP floatpred(oge), %13:_(s32), %14:_
  %16:_(s32) = G_SELECT %15:_(s1), %17:_, %18:_
  G_STORE %16:_(s32), %0:_(p1) :: (store (s32) into %ir.a, addrspace 1)
  SI_RETURN
```

The combiner ``canonicalize_fcmp`` tries to constant fold the two source operands, however, it gets the value from G_FCONSTANT def which is different from the type of the G_FCMP. So the compilation fails with the assert:

```
llc: /llvm-project/llvm/include/llvm/ADT/APFloat.h:1387: llvm::APFloatBase::cmpResult llvm::APFloat::compare(const llvm::APFloat&) const: Assertion `&getSemantics() == &RHS.getSemantics() && "Should only compare APFloats with the same semantics"' failed.

```

The same is reproducible with other targets.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to