Skip to content

Commit

Permalink
[gccjit] add unary testing (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingerZhu authored Nov 29, 2024
1 parent b8cb9b6 commit cf12601
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/Translation/TranslateToGCCJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,15 @@ static gcc_jit_rvalue *translateAtomicOrdering(GCCJITTranslation &trans,
case AtomicOrdering::SeqCst:
gccMemOrder = __ATOMIC_SEQ_CST;
break;
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcovered-switch-default"
#endif
default:
llvm_unreachable("unknown atomic ordering");
#ifdef __clang__
#pragma clang diagnostic pop
#endif
}

gcc_jit_type *gccMemOrderType =
Expand Down
6 changes: 3 additions & 3 deletions test/compile/atomic.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module @test attributes {
^entry(%arg0 : !gccjit.lvalue<!ppi32>, %arg1 : !gccjit.lvalue<!pi32>):
%0 = gccjit.as_rvalue %arg0 : !gccjit.lvalue<!ppi32> to !ppi32
%1 = gccjit.as_rvalue %arg1 : !gccjit.lvalue<!pi32> to !pi32
// CHECK: (void)__atomic_store_8 (((volatile void *)%{{.+}}), (bitcast(%{{.+}}, long long)), (int)0);
// CHECK: (void)__atomic_store_8 (((volatile void *)%{{.+}}), (bitcast(%{{.+}}, {{long long|long}})), (int)0);
gccjit.atomic.store relaxed (%0 : !ppi32, %1 : !pi32)
gccjit.return
}
Expand Down Expand Up @@ -96,7 +96,7 @@ module @test attributes {
^entry(%arg0 : !gccjit.lvalue<!ppi32>, %arg1 : !gccjit.lvalue<!pi32>):
%0 = gccjit.as_rvalue %arg0 : !gccjit.lvalue<!ppi32> to !ppi32
%1 = gccjit.as_rvalue %arg1 : !gccjit.lvalue<!pi32> to !pi32
// CHECK: %{{.+}} = bitcast(__atomic_fetch_add_8 (((volatile void *)%{{.+}}), (bitcast(%{{.+}}, long long)), (int)0), __int32_t *);
// CHECK: %{{.+}} = bitcast(__atomic_fetch_add_8 (((volatile void *)%{{.+}}), (bitcast(%{{.+}}, {{long long|long}})), (int)0), __int32_t *);
%2 = gccjit.atomic.rmw relaxed fetch_add (%0 : !ppi32, %1 : !pi32) : !pi32
gccjit.return %2 : !pi32
}
Expand Down Expand Up @@ -129,7 +129,7 @@ module @test attributes {
%0 = gccjit.as_rvalue %arg0 : !gccjit.lvalue<!ppi32> to !ppi32
%1 = gccjit.as_rvalue %arg1 : !gccjit.lvalue<!ppi32> to !ppi32
%2 = gccjit.as_rvalue %arg2 : !gccjit.lvalue<!pi32> to !pi32
// CHECK: %{{.+}} = __atomic_compare_exchange_8 (((volatile void *)%{{.+}}), ((volatile const void *)%{{.+}}), (bitcast(%{{.+}}, long long)), (bool)1, (int)4, (int)0);
// CHECK: %{{.+}} = __atomic_compare_exchange_8 (((volatile void *)%{{.+}}), ((volatile const void *)%{{.+}}), (bitcast(%{{.+}}, {{long long|long}})), (bool)1, (int)4, (int)0);
%3 = gccjit.atomic.cmpxchg weak success(acq_rel) failure(relaxed) (%0 : !ppi32, %1 : !ppi32, %2 : !pi32) : !bool
gccjit.return %3 : !bool
}
Expand Down
53 changes: 53 additions & 0 deletions test/compile/unary.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// RUN: %gccjit-translate -o %t.gimple %s -mlir-to-gccjit-gimple
// RUN: %filecheck --input-file=%t.gimple %s --check-prefix=CHECK-GIMPLE
!i32 = !gccjit.int<int32_t>
!var32 = !gccjit.lvalue<!i32>
!bool = !gccjit.int<bool>
!varbool = !gccjit.lvalue<!bool>
!float = !gccjit.fp<float>
!varfloat = !gccjit.lvalue<!float>
module @unary_testing {
gccjit.func exported @unary_minus(!i32) -> !i32 {
^body(%arg0: !var32):
// CHECK-GIMPLE: %[[LOAD:[0-9]+]] = %arg0;
%0 = gccjit.as_rvalue %arg0 : !var32 to !i32
// CHECK-GIMPLE: %[[RET:[0-9]+]] = -(%[[LOAD]]);
%1 = gccjit.unary minus (%0 : !i32) : !i32
// CHECK-GIMPLE: return %[[RET]];
gccjit.return %1 : !i32
}
gccjit.func exported @unary_minus_lv(!i32) -> !i32 {
^body(%arg0: !var32):
// CHECK-GIMPLE: %[[RET:[0-9]+]] = -(%arg0);
// CHECK-GIMPLE: return %[[RET]];
%0 = gccjit.unary minus (%arg0 : !var32) : !i32
gccjit.return %0 : !i32
}
gccjit.func exported @unary_bitwise_negate(!i32) -> !i32 {
^body(%arg0: !var32):
// CHECK: return ~(%arg0);
%0 = gccjit.expr lazy {
%1 = gccjit.unary bitwise_negate (%arg0 : !var32) : !i32
gccjit.return %1 : !i32
} : !i32
gccjit.return %0 : !i32
}
gccjit.func exported @unary_logical_negate(!bool) -> !bool {
^body(%arg0: !varbool):
// CHECK: return !(%arg0);
%0 = gccjit.expr lazy {
%1 = gccjit.unary logical_negate (%arg0 : !varbool) : !bool
gccjit.return %1 : !bool
} : !bool
gccjit.return %0 : !bool
}
gccjit.func exported @unary_abs(!float) -> !float {
^body(%arg0: !varfloat):
// CHECK: return abs (%arg0);
%0 = gccjit.expr lazy {
%1 = gccjit.unary abs (%arg0 : !varfloat) : !float
gccjit.return %1 : !float
} : !float
gccjit.return %0 : !float
}
}

0 comments on commit cf12601

Please sign in to comment.