[llvm] a504086 - [InstCombine] add tests for FP casts; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 17 05:41:59 PDT 2022


Author: Sanjay Patel
Date: 2022-06-17T08:41:52-04:00
New Revision: a5040860412f3e61151e427af1cff6ff0aebb775

URL: https://github.com/llvm/llvm-project/commit/a5040860412f3e61151e427af1cff6ff0aebb775
DIFF: https://github.com/llvm/llvm-project/commit/a5040860412f3e61151e427af1cff6ff0aebb775.diff

LOG: [InstCombine] add tests for FP casts; NFC

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/fpcast.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/fpcast.ll b/llvm/test/Transforms/InstCombine/fpcast.ll
index 2390b63753be..f67514c0f427 100644
--- a/llvm/test/Transforms/InstCombine/fpcast.ll
+++ b/llvm/test/Transforms/InstCombine/fpcast.ll
@@ -156,3 +156,202 @@ define half @test_fptrunc_fptrunc(double %V) {
   ret half %t2
 }
 
+define half @sint_to_fptrunc(i32 %x) {
+; CHECK-LABEL: @sint_to_fptrunc(
+; CHECK-NEXT:    [[F:%.*]] = sitofp i32 [[X:%.*]] to float
+; CHECK-NEXT:    [[R:%.*]] = fptrunc float [[F]] to half
+; CHECK-NEXT:    ret half [[R]]
+;
+  %f = sitofp i32 %x to float
+  %r = fptrunc float %f to half
+  ret half %r
+}
+
+define half @masked_sint_to_fptrunc1(i32 %x) {
+; CHECK-LABEL: @masked_sint_to_fptrunc1(
+; CHECK-NEXT:    [[M:%.*]] = and i32 [[X:%.*]], 16777215
+; CHECK-NEXT:    [[F:%.*]] = sitofp i32 [[M]] to float
+; CHECK-NEXT:    [[R:%.*]] = fptrunc float [[F]] to half
+; CHECK-NEXT:    ret half [[R]]
+;
+  %m = and i32 %x, 16777215
+  %f = sitofp i32 %m to float
+  %r = fptrunc float %f to half
+  ret half %r
+}
+
+define half @masked_sint_to_fptrunc2(i32 %x) {
+; CHECK-LABEL: @masked_sint_to_fptrunc2(
+; CHECK-NEXT:    [[M:%.*]] = lshr i32 [[X:%.*]], 8
+; CHECK-NEXT:    [[F:%.*]] = sitofp i32 [[M]] to float
+; CHECK-NEXT:    [[R:%.*]] = fptrunc float [[F]] to half
+; CHECK-NEXT:    ret half [[R]]
+;
+  %m = lshr i32 %x, 8
+  %f = sitofp i32 %m to float
+  %r = fptrunc float %f to half
+  ret half %r
+}
+
+define half @masked_sint_to_fptrunc3(i32 %x) {
+; CHECK-LABEL: @masked_sint_to_fptrunc3(
+; CHECK-NEXT:    [[M:%.*]] = lshr i32 [[X:%.*]], 7
+; CHECK-NEXT:    [[F:%.*]] = sitofp i32 [[M]] to float
+; CHECK-NEXT:    [[R:%.*]] = fptrunc float [[F]] to half
+; CHECK-NEXT:    ret half [[R]]
+;
+  %m = lshr i32 %x, 7
+  %f = sitofp i32 %m to float
+  %r = fptrunc float %f to half
+  ret half %r
+}
+
+define double @sint_to_fpext(i32 %x) {
+; CHECK-LABEL: @sint_to_fpext(
+; CHECK-NEXT:    [[F:%.*]] = sitofp i32 [[X:%.*]] to float
+; CHECK-NEXT:    [[R:%.*]] = fpext float [[F]] to double
+; CHECK-NEXT:    ret double [[R]]
+;
+  %f = sitofp i32 %x to float
+  %r = fpext float %f to double
+  ret double %r
+}
+
+define double @masked_sint_to_fpext1(i32 %x) {
+; CHECK-LABEL: @masked_sint_to_fpext1(
+; CHECK-NEXT:    [[M:%.*]] = and i32 [[X:%.*]], 16777215
+; CHECK-NEXT:    [[F:%.*]] = sitofp i32 [[M]] to float
+; CHECK-NEXT:    [[R:%.*]] = fpext float [[F]] to double
+; CHECK-NEXT:    ret double [[R]]
+;
+  %m = and i32 %x, 16777215
+  %f = sitofp i32 %m to float
+  %r = fpext float %f to double
+  ret double %r
+}
+
+define double @masked_sint_to_fpext2(i32 %x) {
+; CHECK-LABEL: @masked_sint_to_fpext2(
+; CHECK-NEXT:    [[M:%.*]] = lshr i32 [[X:%.*]], 8
+; CHECK-NEXT:    [[F:%.*]] = sitofp i32 [[M]] to float
+; CHECK-NEXT:    [[R:%.*]] = fpext float [[F]] to double
+; CHECK-NEXT:    ret double [[R]]
+;
+  %m = lshr i32 %x, 8
+  %f = sitofp i32 %m to float
+  %r = fpext float %f to double
+  ret double %r
+}
+
+define double @masked_sint_to_fpext3(i32 %x) {
+; CHECK-LABEL: @masked_sint_to_fpext3(
+; CHECK-NEXT:    [[M:%.*]] = lshr i32 [[X:%.*]], 7
+; CHECK-NEXT:    [[F:%.*]] = sitofp i32 [[M]] to float
+; CHECK-NEXT:    [[R:%.*]] = fpext float [[F]] to double
+; CHECK-NEXT:    ret double [[R]]
+;
+  %m = lshr i32 %x, 7
+  %f = sitofp i32 %m to float
+  %r = fpext float %f to double
+  ret double %r
+}
+
+define half @uint_to_fptrunc(i32 %x) {
+; CHECK-LABEL: @uint_to_fptrunc(
+; CHECK-NEXT:    [[F:%.*]] = uitofp i32 [[X:%.*]] to float
+; CHECK-NEXT:    [[R:%.*]] = fptrunc float [[F]] to half
+; CHECK-NEXT:    ret half [[R]]
+;
+  %f = uitofp i32 %x to float
+  %r = fptrunc float %f to half
+  ret half %r
+}
+
+define half @masked_uint_to_fptrunc1(i32 %x) {
+; CHECK-LABEL: @masked_uint_to_fptrunc1(
+; CHECK-NEXT:    [[M:%.*]] = and i32 [[X:%.*]], 16777215
+; CHECK-NEXT:    [[F:%.*]] = uitofp i32 [[M]] to float
+; CHECK-NEXT:    [[R:%.*]] = fptrunc float [[F]] to half
+; CHECK-NEXT:    ret half [[R]]
+;
+  %m = and i32 %x, 16777215
+  %f = uitofp i32 %m to float
+  %r = fptrunc float %f to half
+  ret half %r
+}
+
+define half @masked_uint_to_fptrunc2(i32 %x) {
+; CHECK-LABEL: @masked_uint_to_fptrunc2(
+; CHECK-NEXT:    [[M:%.*]] = lshr i32 [[X:%.*]], 8
+; CHECK-NEXT:    [[F:%.*]] = uitofp i32 [[M]] to float
+; CHECK-NEXT:    [[R:%.*]] = fptrunc float [[F]] to half
+; CHECK-NEXT:    ret half [[R]]
+;
+  %m = lshr i32 %x, 8
+  %f = uitofp i32 %m to float
+  %r = fptrunc float %f to half
+  ret half %r
+}
+
+define half @masked_uint_to_fptrunc3(i32 %x) {
+; CHECK-LABEL: @masked_uint_to_fptrunc3(
+; CHECK-NEXT:    [[M:%.*]] = lshr i32 [[X:%.*]], 7
+; CHECK-NEXT:    [[F:%.*]] = uitofp i32 [[M]] to float
+; CHECK-NEXT:    [[R:%.*]] = fptrunc float [[F]] to half
+; CHECK-NEXT:    ret half [[R]]
+;
+  %m = lshr i32 %x, 7
+  %f = uitofp i32 %m to float
+  %r = fptrunc float %f to half
+  ret half %r
+}
+
+define double @uint_to_fpext(i32 %x) {
+; CHECK-LABEL: @uint_to_fpext(
+; CHECK-NEXT:    [[F:%.*]] = uitofp i32 [[X:%.*]] to float
+; CHECK-NEXT:    [[R:%.*]] = fpext float [[F]] to double
+; CHECK-NEXT:    ret double [[R]]
+;
+  %f = uitofp i32 %x to float
+  %r = fpext float %f to double
+  ret double %r
+}
+
+define double @masked_uint_to_fpext1(i32 %x) {
+; CHECK-LABEL: @masked_uint_to_fpext1(
+; CHECK-NEXT:    [[M:%.*]] = and i32 [[X:%.*]], 16777215
+; CHECK-NEXT:    [[F:%.*]] = uitofp i32 [[M]] to float
+; CHECK-NEXT:    [[R:%.*]] = fpext float [[F]] to double
+; CHECK-NEXT:    ret double [[R]]
+;
+  %m = and i32 %x, 16777215
+  %f = uitofp i32 %m to float
+  %r = fpext float %f to double
+  ret double %r
+}
+
+define double @masked_uint_to_fpext2(i32 %x) {
+; CHECK-LABEL: @masked_uint_to_fpext2(
+; CHECK-NEXT:    [[M:%.*]] = lshr i32 [[X:%.*]], 8
+; CHECK-NEXT:    [[F:%.*]] = uitofp i32 [[M]] to float
+; CHECK-NEXT:    [[R:%.*]] = fpext float [[F]] to double
+; CHECK-NEXT:    ret double [[R]]
+;
+  %m = lshr i32 %x, 8
+  %f = uitofp i32 %m to float
+  %r = fpext float %f to double
+  ret double %r
+}
+
+define double @masked_uint_to_fpext3(i32 %x) {
+; CHECK-LABEL: @masked_uint_to_fpext3(
+; CHECK-NEXT:    [[M:%.*]] = lshr i32 [[X:%.*]], 7
+; CHECK-NEXT:    [[F:%.*]] = uitofp i32 [[M]] to float
+; CHECK-NEXT:    [[R:%.*]] = fpext float [[F]] to double
+; CHECK-NEXT:    ret double [[R]]
+;
+  %m = lshr i32 %x, 7
+  %f = uitofp i32 %m to float
+  %r = fpext float %f to double
+  ret double %r
+}


        


More information about the llvm-commits mailing list