[InstCombine] Allow fptrunc (fpext X)) to be reduced to a single fpext/ftrunc
If we are only truncating bits from the extend we should be able to just use a smaller extend. If we are truncating more than the extend we should be able to just use a fptrunc since the presense of the fpextend shouldn't affect rounding. Differential Revision: https://reviews.llvm.org/D43970 llvm-svn: 326595
This commit is contained in:
parent
20cf67c233
commit
18799f4c07
|
@ -2173,7 +2173,7 @@ unsigned CastInst::isEliminableCastPair(
|
|||
{ 99,99,99, 0, 0,99,99, 0, 0,99,99, 4, 0}, // UIToFP +- firstOp
|
||||
{ 99,99,99, 0, 0,99,99, 0, 0,99,99, 4, 0}, // SIToFP |
|
||||
{ 99,99,99, 0, 0,99,99, 0, 0,99,99, 4, 0}, // FPTrunc |
|
||||
{ 99,99,99, 2, 2,99,99,10, 2,99,99, 4, 0}, // FPExt |
|
||||
{ 99,99,99, 2, 2,99,99, 8, 2,99,99, 4, 0}, // FPExt |
|
||||
{ 1, 0, 0,99,99, 0, 0,99,99,99, 7, 3, 0}, // PtrToInt |
|
||||
{ 99,99,99,99,99,99,99,99,99,11,99,15, 0}, // IntToPtr |
|
||||
{ 5, 5, 5, 6, 6, 5, 5, 6, 6,16, 5, 1,14}, // BitCast |
|
||||
|
@ -2267,12 +2267,6 @@ unsigned CastInst::isEliminableCastPair(
|
|||
case 9:
|
||||
// zext, sext -> zext, because sext can't sign extend after zext
|
||||
return Instruction::ZExt;
|
||||
case 10:
|
||||
// fpext followed by ftrunc is allowed if the bit size returned to is
|
||||
// the same as the original, in which case its just a bitcast
|
||||
if (SrcTy == DstTy)
|
||||
return Instruction::BitCast;
|
||||
return 0; // If the types are not the same we can't eliminate it.
|
||||
case 11: {
|
||||
// inttoptr, ptrtoint -> bitcast if SrcSize<=PtrSize and SrcSize==DstSize
|
||||
if (!MidIntPtrTy)
|
||||
|
|
|
@ -448,8 +448,7 @@ define half @test_mismatched_type_intrin_fabs_fast_double_src(double %D) {
|
|||
define float @test_shrink_intrin_floor_fp16_src(half %C) {
|
||||
; ALL-LABEL: @test_shrink_intrin_floor_fp16_src(
|
||||
; ALL-NEXT: [[E:%.*]] = call half @llvm.floor.f16(half [[C:%.*]])
|
||||
; ALL-NEXT: [[TMP1:%.*]] = fpext half [[E]] to double
|
||||
; ALL-NEXT: [[F:%.*]] = fptrunc double [[TMP1]] to float
|
||||
; ALL-NEXT: [[F:%.*]] = fpext half [[E]] to float
|
||||
; ALL-NEXT: ret float [[F]]
|
||||
;
|
||||
%D = fpext half %C to double
|
||||
|
@ -461,8 +460,7 @@ define float @test_shrink_intrin_floor_fp16_src(half %C) {
|
|||
define float @test_shrink_intrin_ceil_fp16_src(half %C) {
|
||||
; ALL-LABEL: @test_shrink_intrin_ceil_fp16_src(
|
||||
; ALL-NEXT: [[E:%.*]] = call half @llvm.ceil.f16(half [[C:%.*]])
|
||||
; ALL-NEXT: [[TMP1:%.*]] = fpext half [[E]] to double
|
||||
; ALL-NEXT: [[F:%.*]] = fptrunc double [[TMP1]] to float
|
||||
; ALL-NEXT: [[F:%.*]] = fpext half [[E]] to float
|
||||
; ALL-NEXT: ret float [[F]]
|
||||
;
|
||||
%D = fpext half %C to double
|
||||
|
@ -474,8 +472,7 @@ define float @test_shrink_intrin_ceil_fp16_src(half %C) {
|
|||
define float @test_shrink_intrin_round_fp16_src(half %C) {
|
||||
; ALL-LABEL: @test_shrink_intrin_round_fp16_src(
|
||||
; ALL-NEXT: [[E:%.*]] = call half @llvm.round.f16(half [[C:%.*]])
|
||||
; ALL-NEXT: [[TMP1:%.*]] = fpext half [[E]] to double
|
||||
; ALL-NEXT: [[F:%.*]] = fptrunc double [[TMP1]] to float
|
||||
; ALL-NEXT: [[F:%.*]] = fpext half [[E]] to float
|
||||
; ALL-NEXT: ret float [[F]]
|
||||
;
|
||||
%D = fpext half %C to double
|
||||
|
@ -487,8 +484,7 @@ define float @test_shrink_intrin_round_fp16_src(half %C) {
|
|||
define float @test_shrink_intrin_nearbyint_fp16_src(half %C) {
|
||||
; ALL-LABEL: @test_shrink_intrin_nearbyint_fp16_src(
|
||||
; ALL-NEXT: [[E:%.*]] = call half @llvm.nearbyint.f16(half [[C:%.*]])
|
||||
; ALL-NEXT: [[TMP1:%.*]] = fpext half [[E]] to double
|
||||
; ALL-NEXT: [[F:%.*]] = fptrunc double [[TMP1]] to float
|
||||
; ALL-NEXT: [[F:%.*]] = fpext half [[E]] to float
|
||||
; ALL-NEXT: ret float [[F]]
|
||||
;
|
||||
%D = fpext half %C to double
|
||||
|
@ -500,8 +496,7 @@ define float @test_shrink_intrin_nearbyint_fp16_src(half %C) {
|
|||
define float @test_shrink_intrin_trunc_fp16_src(half %C) {
|
||||
; ALL-LABEL: @test_shrink_intrin_trunc_fp16_src(
|
||||
; ALL-NEXT: [[E:%.*]] = call half @llvm.trunc.f16(half [[C:%.*]])
|
||||
; ALL-NEXT: [[TMP1:%.*]] = fpext half [[E]] to double
|
||||
; ALL-NEXT: [[F:%.*]] = fptrunc double [[TMP1]] to float
|
||||
; ALL-NEXT: [[F:%.*]] = fpext half [[E]] to float
|
||||
; ALL-NEXT: ret float [[F]]
|
||||
;
|
||||
%D = fpext half %C to double
|
||||
|
@ -513,8 +508,7 @@ define float @test_shrink_intrin_trunc_fp16_src(half %C) {
|
|||
define float @test_shrink_intrin_fabs_fp16_src(half %C) {
|
||||
; ALL-LABEL: @test_shrink_intrin_fabs_fp16_src(
|
||||
; ALL-NEXT: [[E:%.*]] = call half @llvm.fabs.f16(half [[C:%.*]])
|
||||
; ALL-NEXT: [[TMP1:%.*]] = fpext half [[E]] to double
|
||||
; ALL-NEXT: [[F:%.*]] = fptrunc double [[TMP1]] to float
|
||||
; ALL-NEXT: [[F:%.*]] = fpext half [[E]] to float
|
||||
; ALL-NEXT: ret float [[F]]
|
||||
;
|
||||
%D = fpext half %C to double
|
||||
|
@ -527,8 +521,7 @@ define float @test_shrink_intrin_fabs_fp16_src(half %C) {
|
|||
define float @test_shrink_intrin_fabs_fast_fp16_src(half %C) {
|
||||
; ALL-LABEL: @test_shrink_intrin_fabs_fast_fp16_src(
|
||||
; ALL-NEXT: [[E:%.*]] = call fast half @llvm.fabs.f16(half [[C:%.*]])
|
||||
; ALL-NEXT: [[TMP1:%.*]] = fpext half [[E]] to double
|
||||
; ALL-NEXT: [[F:%.*]] = fptrunc double [[TMP1]] to float
|
||||
; ALL-NEXT: [[F:%.*]] = fpext half [[E]] to float
|
||||
; ALL-NEXT: ret float [[F]]
|
||||
;
|
||||
%D = fpext half %C to double
|
||||
|
|
|
@ -102,8 +102,7 @@ define <2 x float> @not_half_shrinkable(<2 x float> %x) {
|
|||
|
||||
define half @test7(float %a) nounwind {
|
||||
; CHECK-LABEL: @test7(
|
||||
; CHECK-NEXT: [[Y:%.*]] = fpext float [[A:%.*]] to double
|
||||
; CHECK-NEXT: [[Z:%.*]] = fptrunc double [[Y]] to half
|
||||
; CHECK-NEXT: [[Z:%.*]] = fptrunc float [[A:%.*]] to half
|
||||
; CHECK-NEXT: ret half [[Z]]
|
||||
;
|
||||
%y = fpext float %a to double
|
||||
|
@ -113,8 +112,7 @@ define half @test7(float %a) nounwind {
|
|||
|
||||
define float @test8(half %a) nounwind {
|
||||
; CHECK-LABEL: @test8(
|
||||
; CHECK-NEXT: [[Y:%.*]] = fpext half [[A:%.*]] to double
|
||||
; CHECK-NEXT: [[Z:%.*]] = fptrunc double [[Y]] to float
|
||||
; CHECK-NEXT: [[Z:%.*]] = fpext half [[A:%.*]] to float
|
||||
; CHECK-NEXT: ret float [[Z]]
|
||||
;
|
||||
%y = fpext half %a to double
|
||||
|
|
Loading…
Reference in New Issue