diff --git a/llvm/test/Transforms/InstSimplify/fptoi-range.ll b/llvm/test/Transforms/InstSimplify/fptoi-range.ll new file mode 100644 index 000000000000..40a46f6214de --- /dev/null +++ b/llvm/test/Transforms/InstSimplify/fptoi-range.ll @@ -0,0 +1,295 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -S -instsimplify < %s | FileCheck %s + +define i1 @f16_si_max1(half %f) { +; CHECK-LABEL: @f16_si_max1( +; CHECK-NEXT: [[I:%.*]] = fptosi half [[F:%.*]] to i32 +; CHECK-NEXT: [[C:%.*]] = icmp sge i32 [[I]], 65504 +; CHECK-NEXT: ret i1 [[C]] +; + %i = fptosi half %f to i32 + %c = icmp sge i32 %i, 65504 + ret i1 %c +} + +define i1 @f16_si_max2(half %f) { +; CHECK-LABEL: @f16_si_max2( +; CHECK-NEXT: [[I:%.*]] = fptosi half [[F:%.*]] to i32 +; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[I]], 65504 +; CHECK-NEXT: ret i1 [[C]] +; + %i = fptosi half %f to i32 + %c = icmp sgt i32 %i, 65504 + ret i1 %c +} + +define i1 @f16_si16_max2(half %f) { +; CHECK-LABEL: @f16_si16_max2( +; CHECK-NEXT: [[I:%.*]] = fptosi half [[F:%.*]] to i16 +; CHECK-NEXT: [[C:%.*]] = icmp sgt i16 [[I]], -32 +; CHECK-NEXT: ret i1 [[C]] +; + %i = fptosi half %f to i16 + %c = icmp sgt i16 %i, 65504 + ret i1 %c +} + +define i1 @f16_si_min1(half %f) { +; CHECK-LABEL: @f16_si_min1( +; CHECK-NEXT: [[I:%.*]] = fptosi half [[F:%.*]] to i32 +; CHECK-NEXT: [[C:%.*]] = icmp sge i32 [[I]], -65504 +; CHECK-NEXT: ret i1 [[C]] +; + %i = fptosi half %f to i32 + %c = icmp sge i32 %i, -65504 + ret i1 %c +} + +define i1 @f16_si16_min1(half %f) { +; CHECK-LABEL: @f16_si16_min1( +; CHECK-NEXT: [[I:%.*]] = fptosi half [[F:%.*]] to i16 +; CHECK-NEXT: [[C:%.*]] = icmp sge i16 [[I]], 32 +; CHECK-NEXT: ret i1 [[C]] +; + %i = fptosi half %f to i16 + %c = icmp sge i16 %i, -65504 + ret i1 %c +} + +define i1 @f16_si_min2(half %f) { +; CHECK-LABEL: @f16_si_min2( +; CHECK-NEXT: [[I:%.*]] = fptosi half [[F:%.*]] to i32 +; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[I]], -65504 +; CHECK-NEXT: ret i1 [[C]] +; + %i = fptosi half %f to i32 + %c = icmp sgt i32 %i, -65504 + ret i1 %c +} + +define i1 @f16_ui_max1(half %f) { +; CHECK-LABEL: @f16_ui_max1( +; CHECK-NEXT: [[I:%.*]] = fptoui half [[F:%.*]] to i32 +; CHECK-NEXT: [[C:%.*]] = icmp sge i32 [[I]], 65504 +; CHECK-NEXT: ret i1 [[C]] +; + %i = fptoui half %f to i32 + %c = icmp sge i32 %i, 65504 + ret i1 %c +} + +define i1 @f16_ui_max2(half %f) { +; CHECK-LABEL: @f16_ui_max2( +; CHECK-NEXT: [[I:%.*]] = fptoui half [[F:%.*]] to i32 +; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[I]], 65504 +; CHECK-NEXT: ret i1 [[C]] +; + %i = fptoui half %f to i32 + %c = icmp sgt i32 %i, 65504 + ret i1 %c +} + +define i1 @f16_ui16_max2(half %f) { +; CHECK-LABEL: @f16_ui16_max2( +; CHECK-NEXT: [[I:%.*]] = fptoui half [[F:%.*]] to i16 +; CHECK-NEXT: [[C:%.*]] = icmp sgt i16 [[I]], -32 +; CHECK-NEXT: ret i1 [[C]] +; + %i = fptoui half %f to i16 + %c = icmp sgt i16 %i, 65504 + ret i1 %c +} + +define i1 @f16_ui16_max3(half %f) { +; CHECK-LABEL: @f16_ui16_max3( +; CHECK-NEXT: [[I:%.*]] = fptoui half [[F:%.*]] to i16 +; CHECK-NEXT: [[C:%.*]] = icmp ule i16 [[I]], -32 +; CHECK-NEXT: ret i1 [[C]] +; + %i = fptoui half %f to i16 + %c = icmp ule i16 %i, 65504 + ret i1 %c +} + +define i1 @f16_ui_min1(half %f) { +; CHECK-LABEL: @f16_ui_min1( +; CHECK-NEXT: [[I:%.*]] = fptoui half [[F:%.*]] to i32 +; CHECK-NEXT: [[C:%.*]] = icmp sge i32 [[I]], 0 +; CHECK-NEXT: ret i1 [[C]] +; + %i = fptoui half %f to i32 + %c = icmp sge i32 %i, 0 + ret i1 %c +} + +define i1 @f16_ui16_min1(half %f) { +; CHECK-LABEL: @f16_ui16_min1( +; CHECK-NEXT: [[I:%.*]] = fptoui half [[F:%.*]] to i16 +; CHECK-NEXT: [[C:%.*]] = icmp sge i16 [[I]], 0 +; CHECK-NEXT: ret i1 [[C]] +; + %i = fptoui half %f to i16 + %c = icmp sge i16 %i, 0 + ret i1 %c +} + +define i1 @f16_ui_min2(half %f) { +; CHECK-LABEL: @f16_ui_min2( +; CHECK-NEXT: [[I:%.*]] = fptoui half [[F:%.*]] to i32 +; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[I]], 0 +; CHECK-NEXT: ret i1 [[C]] +; + %i = fptoui half %f to i32 + %c = icmp sgt i32 %i, 0 + ret i1 %c +} + + + +define <2 x i1> @v2f16_si_max(<2 x half> %f) { +; CHECK-LABEL: @v2f16_si_max( +; CHECK-NEXT: [[I:%.*]] = fptosi <2 x half> [[F:%.*]] to <2 x i32> +; CHECK-NEXT: [[C:%.*]] = icmp sge <2 x i32> [[I]], +; CHECK-NEXT: ret <2 x i1> [[C]] +; + %i = fptosi <2 x half> %f to <2 x i32> + %c = icmp sge <2 x i32> %i, + ret <2 x i1> %c +} + +define <2 x i1> @v2f16_si_max2(<2 x half> %f) { +; CHECK-LABEL: @v2f16_si_max2( +; CHECK-NEXT: [[I:%.*]] = fptosi <2 x half> [[F:%.*]] to <2 x i32> +; CHECK-NEXT: [[C:%.*]] = icmp sgt <2 x i32> [[I]], +; CHECK-NEXT: ret <2 x i1> [[C]] +; + %i = fptosi <2 x half> %f to <2 x i32> + %c = icmp sgt <2 x i32> %i, + ret <2 x i1> %c +} + +define <2 x i1> @v2f16_si16_max2(<2 x half> %f) { +; CHECK-LABEL: @v2f16_si16_max2( +; CHECK-NEXT: [[I:%.*]] = fptosi <2 x half> [[F:%.*]] to <2 x i16> +; CHECK-NEXT: [[C:%.*]] = icmp sgt <2 x i16> [[I]], +; CHECK-NEXT: ret <2 x i1> [[C]] +; + %i = fptosi <2 x half> %f to <2 x i16> + %c = icmp sgt <2 x i16> %i, + ret <2 x i1> %c +} + +define <2 x i1> @v2f16_si_min1(<2 x half> %f) { +; CHECK-LABEL: @v2f16_si_min1( +; CHECK-NEXT: [[I:%.*]] = fptosi <2 x half> [[F:%.*]] to <2 x i32> +; CHECK-NEXT: [[C:%.*]] = icmp sge <2 x i32> [[I]], +; CHECK-NEXT: ret <2 x i1> [[C]] +; + %i = fptosi <2 x half> %f to <2 x i32> + %c = icmp sge <2 x i32> %i, + ret <2 x i1> %c +} + +define <2 x i1> @v2f16_si16_min1(<2 x half> %f) { +; CHECK-LABEL: @v2f16_si16_min1( +; CHECK-NEXT: [[I:%.*]] = fptosi <2 x half> [[F:%.*]] to <2 x i16> +; CHECK-NEXT: [[C:%.*]] = icmp sge <2 x i16> [[I]], +; CHECK-NEXT: ret <2 x i1> [[C]] +; + %i = fptosi <2 x half> %f to <2 x i16> + %c = icmp sge <2 x i16> %i, + ret <2 x i1> %c +} + +define <2 x i1> @v2f16_si_min2(<2 x half> %f) { +; CHECK-LABEL: @v2f16_si_min2( +; CHECK-NEXT: [[I:%.*]] = fptosi <2 x half> [[F:%.*]] to <2 x i32> +; CHECK-NEXT: [[C:%.*]] = icmp sgt <2 x i32> [[I]], +; CHECK-NEXT: ret <2 x i1> [[C]] +; + %i = fptosi <2 x half> %f to <2 x i32> + %c = icmp sgt <2 x i32> %i, + ret <2 x i1> %c +} + +define <2 x i1> @v2f16_ui_max1(<2 x half> %f) { +; CHECK-LABEL: @v2f16_ui_max1( +; CHECK-NEXT: [[I:%.*]] = fptoui <2 x half> [[F:%.*]] to <2 x i32> +; CHECK-NEXT: [[C:%.*]] = icmp sge <2 x i32> [[I]], +; CHECK-NEXT: ret <2 x i1> [[C]] +; + %i = fptoui <2 x half> %f to <2 x i32> + %c = icmp sge <2 x i32> %i, + ret <2 x i1> %c +} + +define <2 x i1> @v2f16_ui_max2(<2 x half> %f) { +; CHECK-LABEL: @v2f16_ui_max2( +; CHECK-NEXT: [[I:%.*]] = fptoui <2 x half> [[F:%.*]] to <2 x i32> +; CHECK-NEXT: [[C:%.*]] = icmp sgt <2 x i32> [[I]], +; CHECK-NEXT: ret <2 x i1> [[C]] +; + %i = fptoui <2 x half> %f to <2 x i32> + %c = icmp sgt <2 x i32> %i, + ret <2 x i1> %c +} + +define <2 x i1> @v2f16_ui16_max2(<2 x half> %f) { +; CHECK-LABEL: @v2f16_ui16_max2( +; CHECK-NEXT: [[I:%.*]] = fptoui <2 x half> [[F:%.*]] to <2 x i16> +; CHECK-NEXT: [[C:%.*]] = icmp sgt <2 x i16> [[I]], +; CHECK-NEXT: ret <2 x i1> [[C]] +; + %i = fptoui <2 x half> %f to <2 x i16> + %c = icmp sgt <2 x i16> %i, + ret <2 x i1> %c +} + +define <2 x i1> @v2f16_ui16_max3(<2 x half> %f) { +; CHECK-LABEL: @v2f16_ui16_max3( +; CHECK-NEXT: [[I:%.*]] = fptoui <2 x half> [[F:%.*]] to <2 x i16> +; CHECK-NEXT: [[C:%.*]] = icmp ule <2 x i16> [[I]], +; CHECK-NEXT: ret <2 x i1> [[C]] +; + %i = fptoui <2 x half> %f to <2 x i16> + %c = icmp ule <2 x i16> %i, + ret <2 x i1> %c +} + +define <2 x i1> @v2f16_ui_min1(<2 x half> %f) { +; CHECK-LABEL: @v2f16_ui_min1( +; CHECK-NEXT: [[I:%.*]] = fptoui <2 x half> [[F:%.*]] to <2 x i32> +; CHECK-NEXT: [[C:%.*]] = icmp sge <2 x i32> [[I]], zeroinitializer +; CHECK-NEXT: ret <2 x i1> [[C]] +; + %i = fptoui <2 x half> %f to <2 x i32> + %c = icmp sge <2 x i32> %i, + ret <2 x i1> %c +} + +define <2 x i1> @v2f16_ui16_min1(<2 x half> %f) { +; CHECK-LABEL: @v2f16_ui16_min1( +; CHECK-NEXT: [[I:%.*]] = fptoui <2 x half> [[F:%.*]] to <2 x i16> +; CHECK-NEXT: [[C:%.*]] = icmp sge <2 x i16> [[I]], zeroinitializer +; CHECK-NEXT: ret <2 x i1> [[C]] +; + %i = fptoui <2 x half> %f to <2 x i16> + %c = icmp sge <2 x i16> %i, + ret <2 x i1> %c +} + +define <2 x i1> @v2f16_ui_min2(<2 x half> %f) { +; CHECK-LABEL: @v2f16_ui_min2( +; CHECK-NEXT: [[I:%.*]] = fptoui <2 x half> [[F:%.*]] to <2 x i32> +; CHECK-NEXT: [[C:%.*]] = icmp sgt <2 x i32> [[I]], zeroinitializer +; CHECK-NEXT: ret <2 x i1> [[C]] +; + %i = fptoui <2 x half> %f to <2 x i32> + %c = icmp sgt <2 x i32> %i, + ret <2 x i1> %c +} + +declare i32 @llvm.fptosi.sat.i32.f16(half) +declare i32 @llvm.fptoui.sat.i32.f16(half) +declare <2 x i32> @llvm.fptosi.sat.v2i32.v2f16(<2 x half>) +declare <2 x i32> @llvm.fptoui.sat.v2i32.v2f16(<2 x half>)