Skip to content

Commit 6251f7d

Browse files
committed
[InstCombine] Always propagate FMF from fptrunc
1 parent 5a8aa30 commit 6251f7d

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,10 +1917,9 @@ Instruction *InstCombinerImpl::visitFPTrunc(FPTruncInst &FPT) {
19171917
II->getOperandBundlesAsDefs(OpBundles);
19181918
CallInst *NewCI =
19191919
CallInst::Create(Overload, {InnerTrunc}, OpBundles, II->getName());
1920-
NewCI->copyFastMathFlags(II);
1921-
// A normal value may be converted to an infinity.
1922-
if (II->getIntrinsicID() == Intrinsic::fabs)
1923-
NewCI->setHasNoInfs(FPT.hasNoInfs());
1920+
// A normal value may be converted to an infinity. It means that we cannot
1921+
// propagate ninf from the intrinsic. So we propagate FMF from fptrunc.
1922+
NewCI->copyFastMathFlags(&FPT);
19241923
return NewCI;
19251924
}
19261925
}

llvm/test/Transforms/InstCombine/fabs.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,7 @@ define float @test_fabs_nsz_used_by_frem(float %x) {
15221522
define half @test_fabs_nsz_used_by_fptrunc(float %x) {
15231523
; CHECK-LABEL: @test_fabs_nsz_used_by_fptrunc(
15241524
; CHECK-NEXT: [[TMP1:%.*]] = fptrunc float [[X:%.*]] to half
1525-
; CHECK-NEXT: [[OP:%.*]] = call nsz half @llvm.fabs.f16(half [[TMP1]])
1525+
; CHECK-NEXT: [[OP:%.*]] = call half @llvm.fabs.f16(half [[TMP1]])
15261526
; CHECK-NEXT: ret half [[OP]]
15271527
;
15281528
%cmp = fcmp oge float %x, 0.000000e+00

llvm/test/Transforms/InstCombine/fpcast.ll

Lines changed: 1 addition & 1 deletion
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 ninf half @llvm.fabs.f16(half [[TMP1]])
35+
; CHECK-NEXT: [[C:%.*]] = call fast half @llvm.fabs.f16(half [[TMP1]])
3636
; CHECK-NEXT: ret half [[C]]
3737
;
3838
%b = call float @llvm.fabs.f32(float %a)

0 commit comments

Comments
 (0)