diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h index 61f6564e8cd79..478c228755813 100644 --- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h +++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h @@ -1104,16 +1104,22 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase { auto *SrcVTy = dyn_cast(Src); auto *DstVTy = dyn_cast(Dst); + // The SINT_TO_FP and UINT_TO_FP operations check the legality + // based on the src type, not dst type (see SelectionDAGLegalize::LegalizeOp). + const bool useSrcType = + Opcode == Instruction::SIToFP || Opcode == Instruction::UIToFP; + MVT TLIOperationType = useSrcType ? SrcLT.second : DstLT.second; + // If the cast is marked as legal (or promote) then assume low cost. if (SrcLT.first == DstLT.first && - TLI->isOperationLegalOrPromote(ISD, DstLT.second)) + TLI->isOperationLegalOrPromote(ISD, TLIOperationType)) return SrcLT.first; // Handle scalar conversions. if (!SrcVTy && !DstVTy) { // Just check the op cost. If the operation is legal then assume it costs // 1. - if (!TLI->isOperationExpand(ISD, DstLT.second)) + if (!TLI->isOperationExpand(ISD, TLIOperationType)) return 1; // Assume that illegal scalar instruction are expensive. @@ -1136,7 +1142,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase { // Just check the op cost. If the operation is legal then assume it // costs // 1 and multiply by the type-legalization overhead. - if (!TLI->isOperationExpand(ISD, DstLT.second)) + if (!TLI->isOperationExpand(ISD, TLIOperationType)) return SrcLT.first * 1; } diff --git a/llvm/test/Analysis/CostModel/AMDGPU/cast.ll b/llvm/test/Analysis/CostModel/AMDGPU/cast.ll index fc8f5fc393396..da3b01ac54116 100644 --- a/llvm/test/Analysis/CostModel/AMDGPU/cast.ll +++ b/llvm/test/Analysis/CostModel/AMDGPU/cast.ll @@ -248,9 +248,9 @@ define void @sitofp4(<4 x i1> %a, <4 x i8> %b, <4 x i16> %c, <4 x i32> %d) { ; FAST-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %A2 = sitofp <4 x i1> %a to <4 x double> ; FAST-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %B1 = sitofp <4 x i8> %b to <4 x float> ; FAST-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %B2 = sitofp <4 x i8> %b to <4 x double> -; FAST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %C1 = sitofp <4 x i16> %c to <4 x float> +; FAST-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %C1 = sitofp <4 x i16> %c to <4 x float> ; FAST-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %C2 = sitofp <4 x i16> %c to <4 x double> -; FAST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %D1 = sitofp <4 x i32> %d to <4 x float> +; FAST-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %D1 = sitofp <4 x i32> %d to <4 x float> ; FAST-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %D2 = sitofp <4 x i32> %d to <4 x double> ; FAST-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret void ; @@ -261,7 +261,7 @@ define void @sitofp4(<4 x i1> %a, <4 x i8> %b, <4 x i16> %c, <4 x i32> %d) { ; SLOW-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %B2 = sitofp <4 x i8> %b to <4 x double> ; SLOW-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %C1 = sitofp <4 x i16> %c to <4 x float> ; SLOW-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %C2 = sitofp <4 x i16> %c to <4 x double> -; SLOW-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %D1 = sitofp <4 x i32> %d to <4 x float> +; SLOW-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %D1 = sitofp <4 x i32> %d to <4 x float> ; SLOW-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %D2 = sitofp <4 x i32> %d to <4 x double> ; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret void ; @@ -270,9 +270,9 @@ define void @sitofp4(<4 x i1> %a, <4 x i8> %b, <4 x i16> %c, <4 x i32> %d) { ; FAST-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %A2 = sitofp <4 x i1> %a to <4 x double> ; FAST-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %B1 = sitofp <4 x i8> %b to <4 x float> ; FAST-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %B2 = sitofp <4 x i8> %b to <4 x double> -; FAST-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %C1 = sitofp <4 x i16> %c to <4 x float> +; FAST-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %C1 = sitofp <4 x i16> %c to <4 x float> ; FAST-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %C2 = sitofp <4 x i16> %c to <4 x double> -; FAST-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %D1 = sitofp <4 x i32> %d to <4 x float> +; FAST-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %D1 = sitofp <4 x i32> %d to <4 x float> ; FAST-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %D2 = sitofp <4 x i32> %d to <4 x double> ; FAST-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void ; @@ -283,7 +283,7 @@ define void @sitofp4(<4 x i1> %a, <4 x i8> %b, <4 x i16> %c, <4 x i32> %d) { ; SLOW-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %B2 = sitofp <4 x i8> %b to <4 x double> ; SLOW-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %C1 = sitofp <4 x i16> %c to <4 x float> ; SLOW-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %C2 = sitofp <4 x i16> %c to <4 x double> -; SLOW-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %D1 = sitofp <4 x i32> %d to <4 x float> +; SLOW-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %D1 = sitofp <4 x i32> %d to <4 x float> ; SLOW-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %D2 = sitofp <4 x i32> %d to <4 x double> ; SLOW-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void ; @@ -326,9 +326,9 @@ define void @uitofp4(<4 x i1> %a, <4 x i8> %b, <4 x i16> %c, <4 x i32> %d) { ; FAST-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %A2 = uitofp <4 x i1> %a to <4 x double> ; FAST-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %B1 = uitofp <4 x i8> %b to <4 x float> ; FAST-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %B2 = uitofp <4 x i8> %b to <4 x double> -; FAST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %C1 = uitofp <4 x i16> %c to <4 x float> +; FAST-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %C1 = uitofp <4 x i16> %c to <4 x float> ; FAST-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %C2 = uitofp <4 x i16> %c to <4 x double> -; FAST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %D1 = uitofp <4 x i32> %d to <4 x float> +; FAST-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %D1 = uitofp <4 x i32> %d to <4 x float> ; FAST-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %D2 = uitofp <4 x i32> %d to <4 x double> ; FAST-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret void ; @@ -339,7 +339,7 @@ define void @uitofp4(<4 x i1> %a, <4 x i8> %b, <4 x i16> %c, <4 x i32> %d) { ; SLOW-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %B2 = uitofp <4 x i8> %b to <4 x double> ; SLOW-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %C1 = uitofp <4 x i16> %c to <4 x float> ; SLOW-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %C2 = uitofp <4 x i16> %c to <4 x double> -; SLOW-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %D1 = uitofp <4 x i32> %d to <4 x float> +; SLOW-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %D1 = uitofp <4 x i32> %d to <4 x float> ; SLOW-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %D2 = uitofp <4 x i32> %d to <4 x double> ; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret void ; @@ -348,9 +348,9 @@ define void @uitofp4(<4 x i1> %a, <4 x i8> %b, <4 x i16> %c, <4 x i32> %d) { ; FAST-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %A2 = uitofp <4 x i1> %a to <4 x double> ; FAST-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %B1 = uitofp <4 x i8> %b to <4 x float> ; FAST-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %B2 = uitofp <4 x i8> %b to <4 x double> -; FAST-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %C1 = uitofp <4 x i16> %c to <4 x float> +; FAST-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %C1 = uitofp <4 x i16> %c to <4 x float> ; FAST-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %C2 = uitofp <4 x i16> %c to <4 x double> -; FAST-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %D1 = uitofp <4 x i32> %d to <4 x float> +; FAST-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %D1 = uitofp <4 x i32> %d to <4 x float> ; FAST-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %D2 = uitofp <4 x i32> %d to <4 x double> ; FAST-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void ; @@ -361,7 +361,7 @@ define void @uitofp4(<4 x i1> %a, <4 x i8> %b, <4 x i16> %c, <4 x i32> %d) { ; SLOW-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %B2 = uitofp <4 x i8> %b to <4 x double> ; SLOW-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %C1 = uitofp <4 x i16> %c to <4 x float> ; SLOW-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %C2 = uitofp <4 x i16> %c to <4 x double> -; SLOW-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %D1 = uitofp <4 x i32> %d to <4 x float> +; SLOW-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %D1 = uitofp <4 x i32> %d to <4 x float> ; SLOW-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %D2 = uitofp <4 x i32> %d to <4 x double> ; SLOW-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void ;