Skip to content

Commit

Permalink
[gccjit] workaround union access_field problem
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingerZhu committed Nov 15, 2024
1 parent 5e7854d commit cbb58d2
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions test/compile/union.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#gccjit.field<"genius" !gccjit.int<unsigned long>>
}>

!struct2 = !gccjit.struct<"QuaticCat" {
!struct2 = !gccjit.struct<"QuarticCat" {
#gccjit.field<"excellent" !gccjit.fp<float>>,
#gccjit.field<"magnificent" !gccjit.int<long>>
}>
Expand All @@ -27,7 +27,7 @@
#int = #gccjit.int<-1> : !gccjit.int<long>
module attributes { gccjit.opt_level = #gccjit.opt_level<O3>, gccjit.allow_unreachable = true } {

gccjit.global exported @union_data init {
gccjit.global internal @union_data init {
%e = gccjit.const #float
%m = gccjit.const #int
%qc = gccjit.new_struct [0, 1] [%e , %m] : (!gccjit.fp<float>, !gccjit.int<long>) -> !struct2
Expand All @@ -38,30 +38,31 @@ gccjit.global exported @union_data init {
gccjit.func exported @main() -> !gccjit.int<int> {
^entry:
%0 = gccjit.get_global @union_data : !gccjit.lvalue<!union>
// CHECK: %{{[0-9]+}} = union_data.professional.genius;
%1 = gccjit.access_field %0[0] : !gccjit.lvalue<!union> -> !gccjit.lvalue<!struct1>
%2 = gccjit.access_field %1[1] : !gccjit.lvalue<!struct1> -> !gccjit.lvalue<!gccjit.int<unsigned long>>
%3 = gccjit.as_rvalue %2 : !gccjit.lvalue<!gccjit.int<unsigned long>> to !gccjit.int<unsigned long>
%rv = gccjit.as_rvalue %0 : !gccjit.lvalue<!union> to !union
// CHECK: %[[CAST:[0-9]+]] = bitcast(%{{[0-9]+}}, struct Lancern);
%1 = gccjit.bitcast %rv : !union to !struct1
// CHECK: %{{[0-9]+}} = %[[CAST]].genius;
%2 = gccjit.access_field %1[1] : !struct1 -> !gccjit.int<unsigned long>
%max = gccjit.const #gccjit.int<0xffffffffffffffff> : !gccjit.int<unsigned long>
%eq = gccjit.compare eq (%3 : !gccjit.int<unsigned long>, %max : !gccjit.int<unsigned long>) : !gccjit.int<bool>
%eq = gccjit.compare eq (%2 : !gccjit.int<unsigned long>, %max : !gccjit.int<unsigned long>) : !gccjit.int<bool>
gccjit.conditional (%eq : !gccjit.int<bool>), ^next, ^abort

^next:
// CHECK: %[[RV:[0-9]+]] = union_data._float;
%4 = gccjit.access_field %0[2] : !gccjit.lvalue<!union> -> !gccjit.lvalue<!struct3>
%5 = gccjit.as_rvalue %4 : !gccjit.lvalue<!struct3> to !struct3
// CHECK: %[[RV:[0-9]+]] = bitcast(%{{[0-9]+}}, struct Float);
%rv2 = gccjit.access_field %rv[1] : !union -> !struct2
%3 = gccjit.bitcast %rv2 : !struct2 to !struct3
// CHECK: %{{[0-9]+}} = %[[RV]].sign:1;
%6 = gccjit.access_field %5[2] : !struct3 -> !gccjit.int<uint32_t> // sign
%4 = gccjit.access_field %3[2] : !struct3 -> !gccjit.int<uint32_t> // sign
// CHECK: %{{[0-9]+}} = %[[RV]].exp:8;
%7 = gccjit.access_field %5[1] : !struct3 -> !gccjit.int<uint32_t> // exp
%5 = gccjit.access_field %3[1] : !struct3 -> !gccjit.int<uint32_t> // exp
// CHECK: %{{[0-9]+}} = %[[RV]].mant:23;
%8 = gccjit.access_field %5[0] : !struct3 -> !gccjit.int<uint32_t> // mant
%6 = gccjit.access_field %3[0] : !struct3 -> !gccjit.int<uint32_t> // mant
%c0 = gccjit.const #gccjit.int<0> : !gccjit.int<uint32_t>
%exp = gccjit.const #gccjit.int<124> : !gccjit.int<uint32_t>
%mant = gccjit.const #gccjit.int<2097152> : !gccjit.int<uint32_t>
%eq0 = gccjit.compare eq (%6 : !gccjit.int<uint32_t>, %c0 : !gccjit.int<uint32_t>) : !gccjit.int<bool>
%eq1 = gccjit.compare eq (%7 : !gccjit.int<uint32_t>, %exp : !gccjit.int<uint32_t>) : !gccjit.int<bool>
%eq2 = gccjit.compare eq (%8 : !gccjit.int<uint32_t>, %mant : !gccjit.int<uint32_t>) : !gccjit.int<bool>
%eq0 = gccjit.compare eq (%4 : !gccjit.int<uint32_t>, %c0 : !gccjit.int<uint32_t>) : !gccjit.int<bool>
%eq1 = gccjit.compare eq (%5 : !gccjit.int<uint32_t>, %exp : !gccjit.int<uint32_t>) : !gccjit.int<bool>
%eq2 = gccjit.compare eq (%6 : !gccjit.int<uint32_t>, %mant : !gccjit.int<uint32_t>) : !gccjit.int<bool>
%and0 = gccjit.binary logical_and (%eq0 : !gccjit.int<bool>, %eq1 : !gccjit.int<bool>) : !gccjit.int<bool>
%and1 = gccjit.binary logical_and (%and0 : !gccjit.int<bool>, %eq2 : !gccjit.int<bool>) : !gccjit.int<bool>
gccjit.conditional (%and1 : !gccjit.int<bool>), ^return, ^abort
Expand Down

0 comments on commit cbb58d2

Please sign in to comment.