Index: llvm/test/Transforms/InstCombine/icmp-udiv.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/InstCombine/icmp-udiv.ll @@ -0,0 +1,616 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -passes=instcombine -S | FileCheck %s + +; Fold icmp (udiv X, Y), Z. + +define i1 @udiv_icmp_eq_i8(i8 %x, i8 %y, i8 %z) { +; CHECK-LABEL: @udiv_icmp_eq_i8( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i8 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp eq i8 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_eq_i8_commuted(i8 %x, i8 %y, i8 %z) { +; CHECK-LABEL: @udiv_icmp_eq_i8_commuted( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i8 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp eq i8 %z, %1 + ret i1 %2 +} + +define i1 @udiv_icmp_eq_i8_constant(i8 %x, i8 %y) { +; CHECK-LABEL: @udiv_icmp_eq_i8_constant( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i8 [[TMP1]], 5 +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp eq i8 %1, 5 + ret i1 %2 +} + +define i1 @udiv_icmp_eq_i16(i16 %x, i16 %y, i16 %z) { +; CHECK-LABEL: @udiv_icmp_eq_i16( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i16 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i16 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i16 %x, %y + %2 = icmp eq i16 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_eq_i32(i32 %x, i32 %y, i32 %z) { +; CHECK-LABEL: @udiv_icmp_eq_i32( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i32 %x, %y + %2 = icmp eq i32 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_eq_i64(i64 %x, i64 %y, i64 %z) { +; CHECK-LABEL: @udiv_icmp_eq_i64( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i64 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i64 %x, %y + %2 = icmp eq i64 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_eq_i128(i128 %x, i128 %y, i128 %z) { +; CHECK-LABEL: @udiv_icmp_eq_i128( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i128 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i128 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i128 %x, %y + %2 = icmp eq i128 %1, %z + ret i1 %2 +} + +define <2 x i1> @udiv_icmp_eq_i8_vector(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) { +; CHECK-LABEL: @udiv_icmp_eq_i8_vector( +; CHECK-NEXT: [[TMP1:%.*]] = udiv <2 x i8> [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp eq <2 x i8> [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret <2 x i1> [[TMP2]] +; + %1 = udiv <2 x i8> %x, %y + %2 = icmp eq <2 x i8> %1, %z + ret <2 x i1> %2 +} + +define i1 @udiv_icmp_ne_i8(i8 %x, i8 %y, i8 %z) { +; CHECK-LABEL: @udiv_icmp_ne_i8( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i8 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp ne i8 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_ne_i8_commuted(i8 %x, i8 %y, i8 %z) { +; CHECK-LABEL: @udiv_icmp_ne_i8_commuted( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i8 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp ne i8 %z, %1 + ret i1 %2 +} + +define i1 @udiv_icmp_ne_i8_constant(i8 %x, i8 %y) { +; CHECK-LABEL: @udiv_icmp_ne_i8_constant( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i8 [[TMP1]], 5 +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp ne i8 %1, 5 + ret i1 %2 +} + +define i1 @udiv_icmp_ne_i16(i16 %x, i16 %y, i16 %z) { +; CHECK-LABEL: @udiv_icmp_ne_i16( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i16 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i16 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i16 %x, %y + %2 = icmp ne i16 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_ne_i32(i32 %x, i32 %y, i32 %z) { +; CHECK-LABEL: @udiv_icmp_ne_i32( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i32 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i32 %x, %y + %2 = icmp ne i32 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_ne_i64(i64 %x, i64 %y, i64 %z) { +; CHECK-LABEL: @udiv_icmp_ne_i64( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i64 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i64 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i64 %x, %y + %2 = icmp ne i64 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_ne_i128(i128 %x, i128 %y, i128 %z) { +; CHECK-LABEL: @udiv_icmp_ne_i128( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i128 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i128 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i128 %x, %y + %2 = icmp ne i128 %1, %z + ret i1 %2 +} + +define <2 x i1> @udiv_icmp_ne_i8_vector(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) { +; CHECK-LABEL: @udiv_icmp_ne_i8_vector( +; CHECK-NEXT: [[TMP1:%.*]] = udiv <2 x i8> [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ne <2 x i8> [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret <2 x i1> [[TMP2]] +; + %1 = udiv <2 x i8> %x, %y + %2 = icmp ne <2 x i8> %1, %z + ret <2 x i1> %2 +} + +define i1 @udiv_icmp_ugt_i8(i8 %x, i8 %y, i8 %z) { +; CHECK-LABEL: @udiv_icmp_ugt_i8( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt i8 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp ugt i8 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_ugt_reverse_i8(i8 %x, i8 %y, i8 %z) { +; CHECK-LABEL: @udiv_icmp_ugt_reverse_i8( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt i8 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp ult i8 %z, %1 + ret i1 %2 +} + +define i1 @udiv_icmp_ugt_i8_constant(i8 %x, i8 %y) { +; CHECK-LABEL: @udiv_icmp_ugt_i8_constant( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt i8 [[TMP1]], 5 +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp ugt i8 %1, 5 + ret i1 %2 +} + +define i1 @udiv_icmp_ugt_i16(i16 %x, i16 %y, i16 %z) { +; CHECK-LABEL: @udiv_icmp_ugt_i16( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i16 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt i16 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i16 %x, %y + %2 = icmp ugt i16 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_ugt_i32(i32 %x, i32 %y, i32 %z) { +; CHECK-LABEL: @udiv_icmp_ugt_i32( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt i32 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i32 %x, %y + %2 = icmp ugt i32 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_ugt_i64(i64 %x, i64 %y, i64 %z) { +; CHECK-LABEL: @udiv_icmp_ugt_i64( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i64 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt i64 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i64 %x, %y + %2 = icmp ugt i64 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_ugt_i128(i128 %x, i128 %y, i128 %z) { +; CHECK-LABEL: @udiv_icmp_ugt_i128( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i128 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt i128 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i128 %x, %y + %2 = icmp ugt i128 %1, %z + ret i1 %2 +} + +define <2 x i1> @udiv_icmp_ugt_i8_vector(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) { +; CHECK-LABEL: @udiv_icmp_ugt_i8_vector( +; CHECK-NEXT: [[TMP1:%.*]] = udiv <2 x i8> [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt <2 x i8> [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret <2 x i1> [[TMP2]] +; + %1 = udiv <2 x i8> %x, %y + %2 = icmp ugt <2 x i8> %1, %z + ret <2 x i1> %2 +} + +define i1 @udiv_icmp_uge_i8(i8 %x, i8 %y, i8 %z) { +; CHECK-LABEL: @udiv_icmp_uge_i8( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp uge i8 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp uge i8 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_uge_reverse_i8(i8 %x, i8 %y, i8 %z) { +; CHECK-LABEL: @udiv_icmp_uge_reverse_i8( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp uge i8 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp ule i8 %z, %1 + ret i1 %2 +} + +define i1 @udiv_icmp_uge_i8_constant(i8 %x, i8 %y) { +; CHECK-LABEL: @udiv_icmp_uge_i8_constant( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt i8 [[TMP1]], 4 +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp uge i8 %1, 5 + ret i1 %2 +} + +define i1 @udiv_icmp_uge_i16(i16 %x, i16 %y, i16 %z) { +; CHECK-LABEL: @udiv_icmp_uge_i16( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i16 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp uge i16 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i16 %x, %y + %2 = icmp uge i16 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_uge_i32(i32 %x, i32 %y, i32 %z) { +; CHECK-LABEL: @udiv_icmp_uge_i32( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp uge i32 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i32 %x, %y + %2 = icmp uge i32 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_uge_i64(i64 %x, i64 %y, i64 %z) { +; CHECK-LABEL: @udiv_icmp_uge_i64( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i64 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp uge i64 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i64 %x, %y + %2 = icmp uge i64 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_uge_i128(i128 %x, i128 %y, i128 %z) { +; CHECK-LABEL: @udiv_icmp_uge_i128( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i128 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp uge i128 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i128 %x, %y + %2 = icmp uge i128 %1, %z + ret i1 %2 +} + +define <2 x i1> @udiv_icmp_uge_i8_vector(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) { +; CHECK-LABEL: @udiv_icmp_uge_i8_vector( +; CHECK-NEXT: [[TMP1:%.*]] = udiv <2 x i8> [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp uge <2 x i8> [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret <2 x i1> [[TMP2]] +; + %1 = udiv <2 x i8> %x, %y + %2 = icmp uge <2 x i8> %1, %z + ret <2 x i1> %2 +} + +define i1 @udiv_icmp_ult_i8(i8 %x, i8 %y, i8 %z) { +; CHECK-LABEL: @udiv_icmp_ult_i8( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i8 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp ult i8 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_ult_reverse_i8(i8 %x, i8 %y, i8 %z) { +; CHECK-LABEL: @udiv_icmp_ult_reverse_i8( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i8 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp ugt i8 %z, %1 + ret i1 %2 +} + +define i1 @udiv_icmp_ult_i8_constant(i8 %x, i8 %y) { +; CHECK-LABEL: @udiv_icmp_ult_i8_constant( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i8 [[TMP1]], 5 +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp ult i8 %1, 5 + ret i1 %2 +} + +define i1 @udiv_icmp_ult_i16(i16 %x, i16 %y, i16 %z) { +; CHECK-LABEL: @udiv_icmp_ult_i16( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i16 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i16 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i16 %x, %y + %2 = icmp ult i16 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_ult_i32(i32 %x, i32 %y, i32 %z) { +; CHECK-LABEL: @udiv_icmp_ult_i32( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i32 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i32 %x, %y + %2 = icmp ult i32 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_ult_i64(i64 %x, i64 %y, i64 %z) { +; CHECK-LABEL: @udiv_icmp_ult_i64( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i64 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i64 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i64 %x, %y + %2 = icmp ult i64 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_ult_i128(i128 %x, i128 %y, i128 %z) { +; CHECK-LABEL: @udiv_icmp_ult_i128( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i128 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i128 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i128 %x, %y + %2 = icmp ult i128 %1, %z + ret i1 %2 +} + +define <2 x i1> @udiv_icmp_ult_i8_vector(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) { +; CHECK-LABEL: @udiv_icmp_ult_i8_vector( +; CHECK-NEXT: [[TMP1:%.*]] = udiv <2 x i8> [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ult <2 x i8> [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret <2 x i1> [[TMP2]] +; + %1 = udiv <2 x i8> %x, %y + %2 = icmp ult <2 x i8> %1, %z + ret <2 x i1> %2 +} + +define i1 @udiv_icmp_ule_i8(i8 %x, i8 %y, i8 %z) { +; CHECK-LABEL: @udiv_icmp_ule_i8( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ule i8 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp ule i8 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_ule_reverse_i8(i8 %x, i8 %y, i8 %z) { +; CHECK-LABEL: @udiv_icmp_ule_reverse_i8( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ule i8 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp uge i8 %z, %1 + ret i1 %2 +} + +define i1 @udiv_icmp_ule_i8_constant(i8 %x, i8 %y) { +; CHECK-LABEL: @udiv_icmp_ule_i8_constant( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i8 [[TMP1]], 6 +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp ule i8 %1, 5 + ret i1 %2 +} + +define i1 @udiv_icmp_ule_i16(i16 %x, i16 %y, i16 %z) { +; CHECK-LABEL: @udiv_icmp_ule_i16( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i16 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ule i16 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i16 %x, %y + %2 = icmp ule i16 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_ule_i32(i32 %x, i32 %y, i32 %z) { +; CHECK-LABEL: @udiv_icmp_ule_i32( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ule i32 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i32 %x, %y + %2 = icmp ule i32 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_ule_i64(i64 %x, i64 %y, i64 %z) { +; CHECK-LABEL: @udiv_icmp_ule_i64( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i64 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ule i64 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i64 %x, %y + %2 = icmp ule i64 %1, %z + ret i1 %2 +} + +define i1 @udiv_icmp_ule_i128(i128 %x, i128 %y, i128 %z) { +; CHECK-LABEL: @udiv_icmp_ule_i128( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i128 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ule i128 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i128 %x, %y + %2 = icmp ule i128 %1, %z + ret i1 %2 +} + +define <2 x i1> @udiv_icmp_ule_i8_vector(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) { +; CHECK-LABEL: @udiv_icmp_ule_i8_vector( +; CHECK-NEXT: [[TMP1:%.*]] = udiv <2 x i8> [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp ule <2 x i8> [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret <2 x i1> [[TMP2]] +; + %1 = udiv <2 x i8> %x, %y + %2 = icmp ule <2 x i8> %1, %z + ret <2 x i1> %2 +} + +; negative test - multiple usage + +define i1 @udiv_icmp_eq_i8_multiple_usage_fail(i8 %x, i8 %y, i8 %z) { +; CHECK-LABEL: @udiv_icmp_eq_i8_multiple_usage_fail( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i8 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: [[TMP3:%.*]] = mul i8 [[TMP1]], [[TMP1]] +; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i8 [[TMP3]], 0 +; CHECK-NEXT: [[TMP5:%.*]] = or i1 [[TMP2]], [[TMP4]] +; CHECK-NEXT: ret i1 [[TMP5]] +; + %1 = udiv i8 %x, %y + %2 = icmp eq i8 %1, %z + %3 = mul i8 %1, %1 + %4 = icmp eq i8 %3, 0 + %5 = or i1 %2, %4 + ret i1 %5 +} + +; negative test - invalid sdiv operator + +define i1 @udiv_icmp_eq_sdiv_i8_fail(i8 %x, i8 %y, i8 %z) { +; CHECK-LABEL: @udiv_icmp_eq_sdiv_i8_fail( +; CHECK-NEXT: [[TMP1:%.*]] = sdiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i8 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = sdiv i8 %x, %y + %2 = icmp eq i8 %1, %z + ret i1 %2 +} + +; negative test - invalid sgt operator + +define i1 @udiv_icmp_sgt_i8_fail(i8 %x, i8 %y, i8 %z) { +; CHECK-LABEL: @udiv_icmp_sgt_i8_fail( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i8 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp sgt i8 %1, %z + ret i1 %2 +} + +; negative test - invalid sge operator + +define i1 @udiv_icmp_sge_i8_fail(i8 %x, i8 %y, i8 %z) { +; CHECK-LABEL: @udiv_icmp_sge_i8_fail( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp sge i8 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp sge i8 %1, %z + ret i1 %2 +} + +; negative test - invalid slt operator + +define i1 @udiv_icmp_slt_i8_fail(i8 %x, i8 %y, i8 %z) { +; CHECK-LABEL: @udiv_icmp_slt_i8_fail( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp slt i8 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp slt i8 %1, %z + ret i1 %2 +} + +; negative test - invalid sle operator + +define i1 @udiv_icmp_sle_i8_fail(i8 %x, i8 %y, i8 %z) { +; CHECK-LABEL: @udiv_icmp_sle_i8_fail( +; CHECK-NEXT: [[TMP1:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = icmp sle i8 [[TMP1]], [[Z:%.*]] +; CHECK-NEXT: ret i1 [[TMP2]] +; + %1 = udiv i8 %x, %y + %2 = icmp sle i8 %1, %z + ret i1 %2 +}