@@ -739,4 +739,81 @@ extern "C" void test_op_and_fetch (void)
739739 // LLVM: [[RET7:%.*]] = add i64 [[RES7]], [[CONV7]]
740740 // LLVM: store i64 [[RET7]], ptr @ull, align 8
741741 ull = __sync_add_and_fetch (&ull, uc);
742+
743+ // CHECK: [[VAL0:%.*]] = cir.cast(integral, {{%.*}} : !u8i), !s8i
744+ // CHECK: [[RES0:%.*]] = cir.atomic.fetch(sub, {{%.*}} : !cir.ptr<!s8i>, [[VAL0]] : !s8i, seq_cst) fetch_first : !s8i
745+ // CHECK: [[RET0:%.*]] = cir.binop(sub, [[RES0]], [[VAL0]]) : !s8i
746+ // LLVM: [[VAL0:%.*]] = load i8, ptr @uc, align 1
747+ // LLVM: [[RES0:%.*]] = atomicrmw sub ptr @sc, i8 [[VAL0]] seq_cst, align 1
748+ // LLVM: [[RET0:%.*]] = sub i8 [[RES0]], [[VAL0]]
749+ // LLVM: store i8 [[RET0]], ptr @sc, align 1
750+ sc = __sync_sub_and_fetch (&sc, uc);
751+
752+ // CHECK: [[RES1:%.*]] = cir.atomic.fetch(sub, {{%.*}} : !cir.ptr<!u8i>, [[VAL1:%.*]] : !u8i, seq_cst) fetch_first : !u8i
753+ // CHECK: [[RET1:%.*]] = cir.binop(sub, [[RES1]], [[VAL1]]) : !u8i
754+ // LLVM: [[VAL1:%.*]] = load i8, ptr @uc, align 1
755+ // LLVM: [[RES1:%.*]] = atomicrmw sub ptr @uc, i8 [[VAL1]] seq_cst, align 1
756+ // LLVM: [[RET1:%.*]] = sub i8 [[RES1]], [[VAL1]]
757+ // LLVM: store i8 [[RET1]], ptr @uc, align 1
758+ uc = __sync_sub_and_fetch (&uc, uc);
759+
760+ // CHECK: [[VAL2:%.*]] = cir.cast(integral, {{%.*}} : !u8i), !s16i
761+ // CHECK: [[RES2:%.*]] = cir.atomic.fetch(sub, {{%.*}} : !cir.ptr<!s16i>, [[VAL2]] : !s16i, seq_cst) fetch_first : !s16i
762+ // CHECK: [[RET2:%.*]] = cir.binop(sub, [[RES2]], [[VAL2]]) : !s16i
763+ // LLVM: [[VAL2:%.*]] = load i8, ptr @uc, align 1
764+ // LLVM: [[CONV2:%.*]] = zext i8 [[VAL2]] to i16
765+ // LLVM: [[RES2:%.*]] = atomicrmw sub ptr @ss, i16 [[CONV2]] seq_cst, align 2
766+ // LLVM: [[RET2:%.*]] = sub i16 [[RES2]], [[CONV2]]
767+ // LLVM: store i16 [[RET2]], ptr @ss, align 2
768+ ss = __sync_sub_and_fetch (&ss, uc);
769+
770+ // CHECK: [[VAL3:%.*]] = cir.cast(integral, {{%.*}} : !u8i), !u16i
771+ // CHECK: [[RES3:%.*]] = cir.atomic.fetch(sub, {{%.*}} : !cir.ptr<!u16i>, [[VAL3]] : !u16i, seq_cst) fetch_first : !u16i
772+ // CHECK: [[RET3:%.*]] = cir.binop(sub, [[RES3]], [[VAL3]]) : !u16i
773+ // LLVM: [[VAL3:%.*]] = load i8, ptr @uc, align 1
774+ // LLVM: [[CONV3:%.*]] = zext i8 [[VAL3]] to i16
775+ // LLVM: [[RES3:%.*]] = atomicrmw sub ptr @us, i16 [[CONV3]] seq_cst, align 2
776+ // LLVM: [[RET3:%.*]] = sub i16 [[RES3]], [[CONV3]]
777+ // LLVM: store i16 [[RET3]], ptr @us
778+ us = __sync_sub_and_fetch (&us, uc);
779+
780+ // CHECK: [[VAL4:%.*]] = cir.cast(integral, {{%.*}} : !u8i), !s32i
781+ // CHECK: [[RES4:%.*]] = cir.atomic.fetch(sub, {{%.*}} : !cir.ptr<!s32i>, [[VAL4]] : !s32i, seq_cst) fetch_first : !s32i
782+ // CHECK: [[RET4:%.*]] = cir.binop(sub, [[RES4]], [[VAL4]]) : !s32i
783+ // LLVM: [[VAL4:%.*]] = load i8, ptr @uc, align 1
784+ // LLVM: [[CONV4:%.*]] = zext i8 [[VAL4]] to i32
785+ // LLVM: [[RES4:%.*]] = atomicrmw sub ptr @si, i32 [[CONV4]] seq_cst, align 4
786+ // LLVM: [[RET4:%.*]] = sub i32 [[RES4]], [[CONV4]]
787+ // LLVM: store i32 [[RET4]], ptr @si, align 4
788+ si = __sync_sub_and_fetch (&si, uc);
789+
790+ // CHECK: [[VAL5:%.*]] = cir.cast(integral, {{%.*}} : !u8i), !u32i
791+ // CHECK: [[RES5:%.*]] = cir.atomic.fetch(sub, {{%.*}} : !cir.ptr<!u32i>, [[VAL5]] : !u32i, seq_cst) fetch_first : !u32i
792+ // CHECK: [[RET5:%.*]] = cir.binop(sub, [[RES5]], [[VAL5]]) : !u32i
793+ // LLVM: [[VAL5:%.*]] = load i8, ptr @uc, align 1
794+ // LLVM: [[CONV5:%.*]] = zext i8 [[VAL5]] to i32
795+ // LLVM: [[RES5:%.*]] = atomicrmw sub ptr @ui, i32 [[CONV5]] seq_cst, align 4
796+ // LLVM: [[RET5:%.*]] = sub i32 [[RES5]], [[CONV5]]
797+ // LLVM: store i32 [[RET5]], ptr @ui, align 4
798+ ui = __sync_sub_and_fetch (&ui, uc);
799+
800+ // CHECK: [[VAL6:%.*]] = cir.cast(integral, {{%.*}} : !u8i), !s64i
801+ // CHECK: [[RES6:%.*]] = cir.atomic.fetch(sub, {{%.*}} : !cir.ptr<!s64i>, [[VAL6]] : !s64i, seq_cst) fetch_first : !s64i
802+ // CHECK: [[RET6:%.*]] = cir.binop(sub, [[RES6]], [[VAL6]]) : !s64i
803+ // LLVM: [[VAL6:%.*]] = load i8, ptr @uc, align 1
804+ // LLVM: [[CONV6:%.*]] = zext i8 [[VAL6]] to i64
805+ // LLVM: [[RES6:%.*]] = atomicrmw sub ptr @sll, i64 [[CONV6]] seq_cst, align 8
806+ // LLVM: [[RET6:%.*]] = sub i64 [[RES6]], [[CONV6]]
807+ // LLVM: store i64 [[RET6]], ptr @sll, align 8
808+ sll = __sync_sub_and_fetch (&sll, uc);
809+
810+ // CHECK: [[VAL7:%.*]] = cir.cast(integral, {{%.*}} : !u8i), !u64i
811+ // CHECK: [[RES7:%.*]] = cir.atomic.fetch(sub, {{%.*}} : !cir.ptr<!u64i>, [[VAL7]] : !u64i, seq_cst) fetch_first : !u64i
812+ // CHECK: [[RET7:%.*]] = cir.binop(sub, [[RES7]], [[VAL7]]) : !u64i
813+ // LLVM: [[VAL7:%.*]] = load i8, ptr @uc, align 1
814+ // LLVM: [[CONV7:%.*]] = zext i8 [[VAL7]] to i64
815+ // LLVM: [[RES7:%.*]] = atomicrmw sub ptr @ull, i64 [[CONV7]] seq_cst, align 8
816+ // LLVM: [[RET7:%.*]] = sub i64 [[RES7]], [[CONV7]]
817+ // LLVM: store i64 [[RET7]], ptr @ull, align 8
818+ ull = __sync_sub_and_fetch (&ull, uc);
742819}
0 commit comments