1 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
2 ! RUN: bbc -emit-fir -fwrapv %s -o - | FileCheck %s --check-prefix=NO-NSW
4 ! NO-NSW-NOT: overflow<nsw>
6 subroutine subscript(a
, i
, j
, k
)
7 integer :: a(:,:,:), i
, j
, k
10 ! CHECK-LABEL: func.func @_QPsubscript(
11 ! CHECK: %[[VAL_4:.*]] = arith.constant 3 : i32
12 ! CHECK: %[[VAL_5:.*]] = arith.constant 2 : i32
13 ! CHECK: %[[VAL_6:.*]] = arith.constant 1 : i32
14 ! CHECK: %[[VAL_9:.*]] = fir.declare %{{.*}}a"} : (!fir.box<!fir.array<?x?x?xi32>>, !fir.dscope) -> !fir.box<!fir.array<?x?x?xi32>>
15 ! CHECK: %[[VAL_10:.*]] = fir.rebox %[[VAL_9]] : (!fir.box<!fir.array<?x?x?xi32>>) -> !fir.box<!fir.array<?x?x?xi32>>
16 ! CHECK: %[[VAL_11:.*]] = fir.declare %{{.*}}i"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
17 ! CHECK: %[[VAL_12:.*]] = fir.declare %{{.*}}j"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
18 ! CHECK: %[[VAL_13:.*]] = fir.declare %{{.*}}k"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
19 ! CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_11]] : !fir.ref<i32>
20 ! CHECK: %[[VAL_15:.*]] = arith.addi %[[VAL_14]], %[[VAL_6]] overflow<nsw> : i32
21 ! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_15]] : (i32) -> i64
22 ! CHECK: %[[VAL_17:.*]] = fir.load %[[VAL_12]] : !fir.ref<i32>
23 ! CHECK: %[[VAL_18:.*]] = arith.subi %[[VAL_17]], %[[VAL_5]] overflow<nsw> : i32
24 ! CHECK: %[[VAL_19:.*]] = fir.convert %[[VAL_18]] : (i32) -> i64
25 ! CHECK: %[[VAL_20:.*]] = fir.load %[[VAL_13]] : !fir.ref<i32>
26 ! CHECK: %[[VAL_21:.*]] = arith.muli %[[VAL_20]], %[[VAL_4]] overflow<nsw> : i32
27 ! CHECK: %[[VAL_22:.*]] = fir.convert %[[VAL_21]] : (i32) -> i64
28 ! CHECK: %[[VAL_23:.*]] = fir.array_coor %[[VAL_10]] %[[VAL_16]], %[[VAL_19]], %[[VAL_22]] :
30 ! Test that nsw is never added to arith ops
31 ! on vector subscripts.
32 subroutine vector_subscript_as_value(x
, y
, z
)
34 integer(8) :: y(20), z(20)
37 ! CHECK-LABEL: func.func @_QPvector_subscript_as_value(
38 ! CHECK-NOT: overflow<nsw>
41 subroutine vector_subscript_lhs(x
, vector1
, vector2
)
42 integer(8) :: vector1(10), vector2(10)
44 x(vector1
+vector2
) = 42.
46 ! CHECK-LABEL: func.func @_QPvector_subscript_lhs(
47 ! CHECK-NOT: overflow<nsw>
50 ! Test that nsw is never added to arith ops
51 ! on arguments of bitwise comparison intrinsics.
52 subroutine bitwise_comparison(a
, b
)
54 print *, bge(a
+b
, a
-b
)
55 print *, bgt(a
+b
, a
-b
)
56 print *, ble(a
+b
, a
-b
)
57 print *, blt(a
+b
, a
-b
)
59 ! CHECK-LABEL: func.func @_QPbitwise_comparison(
60 ! CHECK-NOT: overflow<nsw>