17
17
#include " AMDGPUInstrInfo.h"
18
18
#include " AMDGPUTargetTransformInfo.h"
19
19
#include " GCNSubtarget.h"
20
+ #include " llvm/ADT/FloatingPointMode.h"
20
21
#include " llvm/IR/IntrinsicsAMDGPU.h"
21
22
#include " llvm/Transforms/InstCombine/InstCombiner.h"
22
23
@@ -417,23 +418,6 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
417
418
break ;
418
419
}
419
420
case Intrinsic::amdgcn_class: {
420
- enum {
421
- S_NAN = 1 << 0 , // Signaling NaN
422
- Q_NAN = 1 << 1 , // Quiet NaN
423
- N_INFINITY = 1 << 2 , // Negative infinity
424
- N_NORMAL = 1 << 3 , // Negative normal
425
- N_SUBNORMAL = 1 << 4 , // Negative subnormal
426
- N_ZERO = 1 << 5 , // Negative zero
427
- P_ZERO = 1 << 6 , // Positive zero
428
- P_SUBNORMAL = 1 << 7 , // Positive subnormal
429
- P_NORMAL = 1 << 8 , // Positive normal
430
- P_INFINITY = 1 << 9 // Positive infinity
431
- };
432
-
433
- const uint32_t FullMask = S_NAN | Q_NAN | N_INFINITY | N_NORMAL |
434
- N_SUBNORMAL | N_ZERO | P_ZERO | P_SUBNORMAL |
435
- P_NORMAL | P_INFINITY;
436
-
437
421
Value *Src0 = II.getArgOperand (0 );
438
422
Value *Src1 = II.getArgOperand (1 );
439
423
const ConstantInt *CMask = dyn_cast<ConstantInt>(Src1);
@@ -452,22 +436,22 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
452
436
uint32_t Mask = CMask->getZExtValue ();
453
437
454
438
// If all tests are made, it doesn't matter what the value is.
455
- if ((Mask & FullMask ) == FullMask ) {
439
+ if ((Mask & fcAllFlags ) == fcAllFlags ) {
456
440
return IC.replaceInstUsesWith (II, ConstantInt::get (II.getType (), true ));
457
441
}
458
442
459
- if ((Mask & FullMask ) == 0 ) {
443
+ if ((Mask & fcAllFlags ) == 0 ) {
460
444
return IC.replaceInstUsesWith (II, ConstantInt::get (II.getType (), false ));
461
445
}
462
446
463
- if (Mask == (S_NAN | Q_NAN) ) {
447
+ if (Mask == fcNan ) {
464
448
// Equivalent of isnan. Replace with standard fcmp.
465
449
Value *FCmp = IC.Builder .CreateFCmpUNO (Src0, Src0);
466
450
FCmp->takeName (&II);
467
451
return IC.replaceInstUsesWith (II, FCmp);
468
452
}
469
453
470
- if (Mask == (N_ZERO | P_ZERO) ) {
454
+ if (Mask == fcZero ) {
471
455
// Equivalent of == 0.
472
456
Value *FCmp =
473
457
IC.Builder .CreateFCmpOEQ (Src0, ConstantFP::get (Src0->getType (), 0.0 ));
@@ -477,10 +461,9 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
477
461
}
478
462
479
463
// fp_class (nnan x), qnan|snan|other -> fp_class (nnan x), other
480
- if (((Mask & S_NAN) || (Mask & Q_NAN)) &&
481
- isKnownNeverNaN (Src0, &IC.getTargetLibraryInfo ())) {
464
+ if ((Mask & fcNan) && isKnownNeverNaN (Src0, &IC.getTargetLibraryInfo ())) {
482
465
return IC.replaceOperand (
483
- II, 1 , ConstantInt::get (Src1->getType (), Mask & ~(S_NAN | Q_NAN) ));
466
+ II, 1 , ConstantInt::get (Src1->getType (), Mask & ~fcNan ));
484
467
}
485
468
486
469
const ConstantFP *CVal = dyn_cast<ConstantFP>(Src0);
@@ -490,10 +473,10 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
490
473
}
491
474
492
475
// Clamp mask to used bits
493
- if ((Mask & FullMask ) != Mask) {
476
+ if ((Mask & fcAllFlags ) != Mask) {
494
477
CallInst *NewCall = IC.Builder .CreateCall (
495
478
II.getCalledFunction (),
496
- {Src0, ConstantInt::get (Src1->getType (), Mask & FullMask )});
479
+ {Src0, ConstantInt::get (Src1->getType (), Mask & fcAllFlags )});
497
480
498
481
NewCall->takeName (&II);
499
482
return IC.replaceInstUsesWith (II, NewCall);
@@ -505,16 +488,16 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
505
488
const APFloat &Val = CVal->getValueAPF ();
506
489
507
490
bool Result =
508
- ((Mask & S_NAN ) && Val.isNaN () && Val.isSignaling ()) ||
509
- ((Mask & Q_NAN ) && Val.isNaN () && !Val.isSignaling ()) ||
510
- ((Mask & N_INFINITY ) && Val.isInfinity () && Val.isNegative ()) ||
511
- ((Mask & N_NORMAL ) && Val.isNormal () && Val.isNegative ()) ||
512
- ((Mask & N_SUBNORMAL ) && Val.isDenormal () && Val.isNegative ()) ||
513
- ((Mask & N_ZERO ) && Val.isZero () && Val.isNegative ()) ||
514
- ((Mask & P_ZERO ) && Val.isZero () && !Val.isNegative ()) ||
515
- ((Mask & P_SUBNORMAL ) && Val.isDenormal () && !Val.isNegative ()) ||
516
- ((Mask & P_NORMAL ) && Val.isNormal () && !Val.isNegative ()) ||
517
- ((Mask & P_INFINITY ) && Val.isInfinity () && !Val.isNegative ());
491
+ ((Mask & fcSNan ) && Val.isNaN () && Val.isSignaling ()) ||
492
+ ((Mask & fcQNan ) && Val.isNaN () && !Val.isSignaling ()) ||
493
+ ((Mask & fcNegInf ) && Val.isInfinity () && Val.isNegative ()) ||
494
+ ((Mask & fcNegNormal ) && Val.isNormal () && Val.isNegative ()) ||
495
+ ((Mask & fcNegSubnormal ) && Val.isDenormal () && Val.isNegative ()) ||
496
+ ((Mask & fcNegZero ) && Val.isZero () && Val.isNegative ()) ||
497
+ ((Mask & fcPosZero ) && Val.isZero () && !Val.isNegative ()) ||
498
+ ((Mask & fcPosSubnormal ) && Val.isDenormal () && !Val.isNegative ()) ||
499
+ ((Mask & fcPosNormal ) && Val.isNormal () && !Val.isNegative ()) ||
500
+ ((Mask & fcPosInf ) && Val.isInfinity () && !Val.isNegative ());
518
501
519
502
return IC.replaceInstUsesWith (II, ConstantInt::get (II.getType (), Result));
520
503
}
0 commit comments