Skip to content

Commit 473b9ed

Browse files
committed
[InstCombine] Add support for ret nofpclass
1 parent b314ab2 commit 473b9ed

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "InstCombineInternal.h"
1414
#include "llvm/ADT/APInt.h"
15+
#include "llvm/ADT/FloatingPointMode.h"
1516
#include "llvm/ADT/STLExtras.h"
1617
#include "llvm/ADT/SmallVector.h"
1718
#include "llvm/Analysis/AssumptionCache.h"
@@ -2853,6 +2854,9 @@ static bool ignoreSignBitOfNaN(Instruction &I) {
28532854
case Instruction::Select:
28542855
case Instruction::PHI:
28552856
return false;
2857+
case Instruction::Ret:
2858+
return I.getFunction()->getAttributes().getRetNoFPClass() &
2859+
FPClassTest::fcNan;
28562860
case Instruction::Call:
28572861
case Instruction::Invoke: {
28582862
if (auto *II = dyn_cast<IntrinsicInst>(User)) {

llvm/test/Transforms/InstCombine/fabs.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,17 @@ define void @test_fabs_used_by_nofpclass_nan(float %x) {
13801380
ret void
13811381
}
13821382

1383+
define nofpclass(nan) float @test_fabs_used_by_ret_nofpclass_nan(float %x) {
1384+
; CHECK-LABEL: @test_fabs_used_by_ret_nofpclass_nan(
1385+
; CHECK-NEXT: [[SEL:%.*]] = call nsz float @llvm.fabs.f32(float [[X:%.*]])
1386+
; CHECK-NEXT: ret float [[SEL]]
1387+
;
1388+
%cmp = fcmp oge float %x, 0.000000e+00
1389+
%neg = fneg float %x
1390+
%sel = select nsz i1 %cmp, float %x, float %neg
1391+
ret float %sel
1392+
}
1393+
13831394
define i32 @test_fabs_used_fptosi(float %x) {
13841395
; CHECK-LABEL: @test_fabs_used_fptosi(
13851396
; CHECK-NEXT: [[SEL:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]])

0 commit comments

Comments
 (0)