[llvm] r326595 - [InstCombine] Allow fptrunc (fpext X)) to be reduced to a single fpext/ftrunc
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 2 10:16:51 PST 2018
Author: ctopper
Date: Fri Mar 2 10:16:51 2018
New Revision: 326595
URL: http://llvm.org/viewvc/llvm-project?rev=326595&view=rev
Log:
[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
Modified:
llvm/trunk/lib/IR/Instructions.cpp
llvm/trunk/test/Transforms/InstCombine/double-float-shrink-2.ll
llvm/trunk/test/Transforms/InstCombine/fpextend.ll
Modified: llvm/trunk/lib/IR/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Instructions.cpp?rev=326595&r1=326594&r2=326595&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Instructions.cpp (original)
+++ llvm/trunk/lib/IR/Instructions.cpp Fri Mar 2 10:16:51 2018
@@ -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)
Modified: llvm/trunk/test/Transforms/InstCombine/double-float-shrink-2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/double-float-shrink-2.ll?rev=326595&r1=326594&r2=326595&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/double-float-shrink-2.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/double-float-shrink-2.ll Fri Mar 2 10:16:51 2018
@@ -448,8 +448,7 @@ define half @test_mismatched_type_intrin
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_f
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_fp
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_f
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_nearbyi
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_f
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_fp
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
Modified: llvm/trunk/test/Transforms/InstCombine/fpextend.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fpextend.ll?rev=326595&r1=326594&r2=326595&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fpextend.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fpextend.ll Fri Mar 2 10:16:51 2018
@@ -102,8 +102,7 @@ define <2 x float> @not_half_shrinkable(
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
More information about the llvm-commits
mailing list