[llvm] 130a235 - [InstCombine] add tests for FP cast of cast; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sun May 17 08:43:08 PDT 2020
Author: Sanjay Patel
Date: 2020-05-17T11:42:07-04:00
New Revision: 130a2356aee7d8326af4635791d40a19e582a5f0
URL: https://github.com/llvm/llvm-project/commit/130a2356aee7d8326af4635791d40a19e582a5f0
DIFF: https://github.com/llvm/llvm-project/commit/130a2356aee7d8326af4635791d40a19e582a5f0.diff
LOG: [InstCombine] add tests for FP cast of cast; NFC
A fold of casts is proposed as a backend transform in D79187,
but we can also do that in IR (and that may obsolete the need
for a backend transform).
Added:
Modified:
llvm/test/Transforms/InstCombine/fptrunc.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/fptrunc.ll b/llvm/test/Transforms/InstCombine/fptrunc.ll
index e8038f4b8460..9c9ee11a32c2 100644
--- a/llvm/test/Transforms/InstCombine/fptrunc.ll
+++ b/llvm/test/Transforms/InstCombine/fptrunc.ll
@@ -136,3 +136,58 @@ define float @fptrunc_select_true_val_type_mismatch_fast(half %x, double %y, i1
%r = fptrunc double %sel to float
ret float %r
}
+
+; Convert from integer is exact, so convert directly to float.
+
+define <2 x float> @ItoFtoF_s54_f64_f32(<2 x i54> %i) {
+; CHECK-LABEL: @ItoFtoF_s54_f64_f32(
+; CHECK-NEXT: [[X:%.*]] = sitofp <2 x i54> [[I:%.*]] to <2 x double>
+; CHECK-NEXT: [[R:%.*]] = fptrunc <2 x double> [[X]] to <2 x float>
+; CHECK-NEXT: ret <2 x float> [[R]]
+;
+ %x = sitofp <2 x i54> %i to <2 x double>
+ %r = fptrunc <2 x double> %x to <2 x float>
+ ret <2 x float> %r
+}
+
+; Convert from integer is exact, so convert directly to half.
+; Extra use is ok.
+
+define half @ItoFtoF_u24_f32_f16(i24 %i) {
+; CHECK-LABEL: @ItoFtoF_u24_f32_f16(
+; CHECK-NEXT: [[X:%.*]] = uitofp i24 [[I:%.*]] to float
+; CHECK-NEXT: call void @use(float [[X]])
+; CHECK-NEXT: [[R:%.*]] = fptrunc float [[X]] to half
+; CHECK-NEXT: ret half [[R]]
+;
+ %x = uitofp i24 %i to float
+ call void @use(float %x)
+ %r = fptrunc float %x to half
+ ret half %r
+}
+
+; Negative test - intermediate rounding in float type.
+
+define float @ItoFtoF_s55_f64_f32(i55 %i) {
+; CHECK-LABEL: @ItoFtoF_s55_f64_f32(
+; CHECK-NEXT: [[X:%.*]] = sitofp i55 [[I:%.*]] to double
+; CHECK-NEXT: [[R:%.*]] = fptrunc double [[X]] to float
+; CHECK-NEXT: ret float [[R]]
+;
+ %x = sitofp i55 %i to double
+ %r = fptrunc double %x to float
+ ret float %r
+}
+
+; Negative test - intermediate rounding in float type.
+
+define half @ItoFtoF_u25_f32_f16(i25 %i) {
+; CHECK-LABEL: @ItoFtoF_u25_f32_f16(
+; CHECK-NEXT: [[X:%.*]] = uitofp i25 [[I:%.*]] to float
+; CHECK-NEXT: [[R:%.*]] = fptrunc float [[X]] to half
+; CHECK-NEXT: ret half [[R]]
+;
+ %x = uitofp i25 %i to float
+ %r = fptrunc float %x to half
+ ret half %r
+}
More information about the llvm-commits
mailing list