@@ -699,4 +699,105 @@ func.func @trip_count_arith_add_nuw_loop_unsigned_invalid(%lb : i32, %other : i3
699699 scf.yield %arg0 : i32
700700 }
701701 return %1 : i32
702+ }
703+
704+ // -----
705+
706+ // CHECK-LABEL:func.func @trip_count_i8_unsigned_full_range(
707+ func.func @trip_count_i8_unsigned_full_range (%a : i32 , %b : i32 ) -> i32 {
708+ %c0 = arith.constant 0 : i8
709+ %c255 = arith.constant 255 : i8
710+ %c1 = arith.constant 1 : i8
711+
712+ // Unsigned i8 from 0 to 255: trip count is 255
713+ // Trip counts are returned in their natural bitwidth and printed as signed.
714+ // 255 in i8 is represented as -1 when printed in signed format.
715+ // CHECK: "test.trip-count" = -1 : i8
716+ %r = scf.for unsigned %i = %c0 to %c255 step %c1 iter_args (%0 = %a ) -> i32 : i8 {
717+ scf.yield %b : i32
718+ }
719+ return %r : i32
720+ }
721+
722+ // -----
723+
724+ // CHECK-LABEL:func.func @trip_count_i8_unsigned_partial_range(
725+ func.func @trip_count_i8_unsigned_partial_range (%a : i32 , %b : i32 ) -> i32 {
726+ %c0 = arith.constant 0 : i8
727+ %c200 = arith.constant 200 : i8
728+ %c1 = arith.constant 1 : i8
729+
730+ // Unsigned i8 from 0 to 200: trip count is 200
731+ // 200 in i8 is represented as -56 when printed in signed format.
732+ // CHECK: "test.trip-count" = -56 : i8
733+ %r = scf.for unsigned %i = %c0 to %c200 step %c1 iter_args (%0 = %a ) -> i32 : i8 {
734+ scf.yield %b : i32
735+ }
736+ return %r : i32
737+ }
738+
739+ // -----
740+
741+ // CHECK-LABEL:func.func @trip_count_i8_unsigned_high_range(
742+ func.func @trip_count_i8_unsigned_high_range (%a : i32 , %b : i32 ) -> i32 {
743+ %c200 = arith.constant 200 : i8
744+ %c255 = arith.constant 255 : i8
745+ %c1 = arith.constant 1 : i8
746+
747+ // Unsigned i8 from 200 to 255: trip count is 55
748+ // CHECK: "test.trip-count" = 55 : i8
749+ %r = scf.for unsigned %i = %c200 to %c255 step %c1 iter_args (%0 = %a ) -> i32 : i8 {
750+ scf.yield %b : i32
751+ }
752+ return %r : i32
753+ }
754+
755+ // -----
756+
757+ // CHECK-LABEL:func.func @trip_count_i8_signed_crossing_zero(
758+ func.func @trip_count_i8_signed_crossing_zero (%a : i32 , %b : i32 ) -> i32 {
759+ %c -128 = arith.constant -128 : i32
760+ %c127 = arith.constant 127 : i32
761+ %c1 = arith.constant 1 : i32
762+
763+ // Signed i32 from -128 to 127, crossing zero
764+ // CHECK: "test.trip-count" = 255
765+ %r = scf.for %i = %c -128 to %c127 step %c1 iter_args (%0 = %a ) -> i32 : i32 {
766+ scf.yield %b : i32
767+ }
768+ return %r : i32
769+ }
770+
771+ // -----
772+
773+ // CHECK-LABEL:func.func @trip_count_i16_unsigned_full_range(
774+ func.func @trip_count_i16_unsigned_full_range (%a : i32 , %b : i32 ) -> i32 {
775+ %c0 = arith.constant 0 : i16
776+ %c65535 = arith.constant 65535 : i16
777+ %c1 = arith.constant 1 : i16
778+
779+ // Unsigned i16 from 0 to 65535: trip count is 65535
780+ // 65535 in i16 is represented as -1 when printed in signed format.
781+ // CHECK: "test.trip-count" = -1 : i16
782+ %r = scf.for unsigned %i = %c0 to %c65535 step %c1 iter_args (%0 = %a ) -> i32 : i16 {
783+ scf.yield %b : i32
784+ }
785+ return %r : i32
786+ }
787+
788+ // -----
789+
790+ // CHECK-LABEL:func.func @trip_count_i8_unsigned_step_2(
791+ func.func @trip_count_i8_unsigned_step_2 (%a : i32 , %b : i32 ) -> i32 {
792+ %c0 = arith.constant 0 : i8
793+ %c255 = arith.constant 255 : i8
794+ %c2 = arith.constant 2 : i8
795+
796+ // Unsigned i8 from 0 to 255 step 2: trip count is 128 (255/2 rounded up)
797+ // 128 in i8 is represented as -128 when printed in signed format.
798+ // CHECK: "test.trip-count" = -128 : i8
799+ %r = scf.for unsigned %i = %c0 to %c255 step %c2 iter_args (%0 = %a ) -> i32 : i8 {
800+ scf.yield %b : i32
801+ }
802+ return %r : i32
702803}
0 commit comments