Skip to content

Commit 2b1fe7e

Browse files
committed
[InstCombine] Drop ninf when folding fptrunc(fabs(X)) -> fabs()fpfptrunc X)
1 parent 332aa18 commit 2b1fe7e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,6 +1918,9 @@ Instruction *InstCombinerImpl::visitFPTrunc(FPTruncInst &FPT) {
19181918
CallInst *NewCI =
19191919
CallInst::Create(Overload, {InnerTrunc}, OpBundles, II->getName());
19201920
NewCI->copyFastMathFlags(II);
1921+
// A normal value may be converted to an infinity.
1922+
if (II->getIntrinsicID() == Intrinsic::fabs)
1923+
NewCI->setHasNoInfs(FPT.hasNoInfs());
19211924
return NewCI;
19221925
}
19231926
}

llvm/test/Transforms/InstCombine/fpcast.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ define half @test3(float %a) {
3232
define half @test3_fast(float %a) {
3333
; CHECK-LABEL: @test3_fast(
3434
; CHECK-NEXT: [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
35-
; CHECK-NEXT: [[C:%.*]] = call half @llvm.fabs.f16(half [[TMP1]])
35+
; CHECK-NEXT: [[C:%.*]] = call ninf half @llvm.fabs.f16(half [[TMP1]])
3636
; CHECK-NEXT: ret half [[C]]
3737
;
3838
%b = call float @llvm.fabs.f32(float %a)
@@ -54,7 +54,7 @@ define half @test3_both_ninf(float %a) {
5454
define half @test3_fabs_ninf(float %a) {
5555
; CHECK-LABEL: @test3_fabs_ninf(
5656
; CHECK-NEXT: [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
57-
; CHECK-NEXT: [[C:%.*]] = call ninf half @llvm.fabs.f16(half [[TMP1]])
57+
; CHECK-NEXT: [[C:%.*]] = call half @llvm.fabs.f16(half [[TMP1]])
5858
; CHECK-NEXT: ret half [[C]]
5959
;
6060
%b = call ninf float @llvm.fabs.f32(float %a)

0 commit comments

Comments
 (0)