@@ -60,26 +60,6 @@ static APFloat fmed3AMDGCN(const APFloat &Src0, const APFloat &Src1,
6060 return maxnum (Src0, Src1);
6161}
6262
63- // Constant fold llvm.amdgcn.smed3 intrinsics for standard inputs.
64- static APInt smed3AMDGCN (const APInt &Src0, const APInt &Src1, const APInt &Src2) {
65- APInt Max3 = Src0.sgt (Src1) ? (Src0.sgt (Src2) ? Src0 : Src2)
66- : (Src1.sgt (Src2) ? Src1 : Src2);
67-
68- if (Max3 == Src0) return Src1.sgt (Src2) ? Src1 : Src2;
69- if (Max3 == Src1) return Src0.sgt (Src2) ? Src0 : Src2;
70- return Src0.sgt (Src1) ? Src0 : Src1;
71- }
72-
73- // Constant fold llvm.amdgcn.umed3 intrinsics for standard inputs.
74- static APInt umed3AMDGCN (const APInt &Src0, const APInt &Src1, const APInt &Src2) {
75- APInt Max3 = Src0.ugt (Src1) ? (Src0.ugt (Src2) ? Src0 : Src2)
76- : (Src1.ugt (Src2) ? Src1 : Src2);
77-
78- if (Max3 == Src0) return Src1.ugt (Src2) ? Src1 : Src2;
79- if (Max3 == Src1) return Src0.ugt (Src2) ? Src0 : Src2;
80- return Src0.ugt (Src1) ? Src0 : Src1;
81- }
82-
8363// Check if a value can be converted to a 16-bit value without losing
8464// precision.
8565// The value is expected to be either a float (IsFloat = true) or an unsigned
@@ -447,36 +427,6 @@ static Value *matchFPExtFromF16(Value *Arg) {
447427 return nullptr ;
448428}
449429
450- // / Match an sext from i16 to i32, or a constant we can convert.
451- static Value *matchSExtFromI16 (Value *Arg) {
452- Value *Src = nullptr ;
453- ConstantInt *CInt = nullptr ;
454- if (match (Arg, m_OneUse (m_SExt (m_Value (Src))))) {
455- if (Src->getType ()->isIntegerTy (16 ))
456- return Src;
457- } else if (match (Arg, m_ConstantInt (CInt))) {
458- // Check if the constant fits in i16
459- if (CInt->getValue ().getActiveBits () <= 16 )
460- return ConstantInt::get (Type::getInt16Ty (Arg->getContext ()), CInt->getValue ().trunc (16 ));
461- }
462- return nullptr ;
463- }
464-
465- // / Match a zext from i16 to i32, or a constant we can convert.
466- static Value *matchZExtFromI16 (Value *Arg) {
467- Value *Src = nullptr ;
468- ConstantInt *CInt = nullptr ;
469- if (match (Arg, m_OneUse (m_ZExt (m_Value (Src))))) {
470- if (Src->getType ()->isIntegerTy (16 ))
471- return Src;
472- } else if (match (Arg, m_ConstantInt (CInt))) {
473- // Check if the constant fits in i16
474- if (CInt->getValue ().getActiveBits () <= 16 )
475- return ConstantInt::get (Type::getInt16Ty (Arg->getContext ()), CInt->getValue ().trunc (16 ));
476- }
477- return nullptr ;
478- }
479-
480430// Trim all zero components from the end of the vector \p UseV and return
481431// an appropriate bitset with known elements.
482432static APInt trimTrailingZerosInVector (InstCombiner &IC, Value *UseV,
@@ -1224,128 +1174,6 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
12241174
12251175 break ;
12261176 }
1227- case Intrinsic::amdgcn_smed3: {
1228- Value *Src0 = II.getArgOperand (0 );
1229- Value *Src1 = II.getArgOperand (1 );
1230- Value *Src2 = II.getArgOperand (2 );
1231-
1232- // Propagate poison values.
1233- for (Value *Src : {Src0, Src1, Src2}) {
1234- if (isa<PoisonValue>(Src))
1235- return IC.replaceInstUsesWith (II, Src);
1236- }
1237-
1238- bool Swap = false ;
1239- // Canonicalize constants to RHS operands.
1240- //
1241- // smed3(c0, x, c1) -> smed3(x, c0, c1)
1242- if (isa<Constant>(Src0) && !isa<Constant>(Src1)) {
1243- std::swap (Src0, Src1);
1244- Swap = true ;
1245- }
1246-
1247- if (isa<Constant>(Src1) && !isa<Constant>(Src2)) {
1248- std::swap (Src1, Src2);
1249- Swap = true ;
1250- }
1251-
1252- if (isa<Constant>(Src0) && !isa<Constant>(Src1)) {
1253- std::swap (Src0, Src1);
1254- Swap = true ;
1255- }
1256-
1257- if (Swap) {
1258- II.setArgOperand (0 , Src0);
1259- II.setArgOperand (1 , Src1);
1260- II.setArgOperand (2 , Src2);
1261- return &II;
1262- }
1263-
1264- // Constant fold smed3 with constant operands.
1265- if (const ConstantInt *C0 = dyn_cast<ConstantInt>(Src0)) {
1266- if (const ConstantInt *C1 = dyn_cast<ConstantInt>(Src1)) {
1267- if (const ConstantInt *C2 = dyn_cast<ConstantInt>(Src2)) {
1268- APInt Result = smed3AMDGCN (C0->getValue (), C1->getValue (), C2->getValue ());
1269- return IC.replaceInstUsesWith (II, ConstantInt::get (II.getType (), Result));
1270- }
1271- }
1272- }
1273-
1274- // Width reduction for integer extensions.
1275- // smed3((sext X), (sext Y), (sext Z)) -> sext (smed3(X, Y, Z))
1276- if (Value *X = matchSExtFromI16 (Src0)) {
1277- if (Value *Y = matchSExtFromI16 (Src1)) {
1278- if (Value *Z = matchSExtFromI16 (Src2)) {
1279- Value *NewCall = IC.Builder .CreateIntrinsic (
1280- IID, {X->getType ()}, {X, Y, Z}, &II, II.getName ());
1281- return new SExtInst (NewCall, II.getType ());
1282- }
1283- }
1284- }
1285-
1286- break ;
1287- }
1288- case Intrinsic::amdgcn_umed3: {
1289- Value *Src0 = II.getArgOperand (0 );
1290- Value *Src1 = II.getArgOperand (1 );
1291- Value *Src2 = II.getArgOperand (2 );
1292-
1293- // Propagate poison values.
1294- for (Value *Src : {Src0, Src1, Src2}) {
1295- if (isa<PoisonValue>(Src))
1296- return IC.replaceInstUsesWith (II, Src);
1297- }
1298-
1299- bool Swap = false ;
1300- // Canonicalize constants to RHS operands.
1301- //
1302- // umed3(c0, x, c1) -> umed3(x, c0, c1)
1303- if (isa<Constant>(Src0) && !isa<Constant>(Src1)) {
1304- std::swap (Src0, Src1);
1305- Swap = true ;
1306- }
1307-
1308- if (isa<Constant>(Src1) && !isa<Constant>(Src2)) {
1309- std::swap (Src1, Src2);
1310- Swap = true ;
1311- }
1312-
1313- if (isa<Constant>(Src0) && !isa<Constant>(Src1)) {
1314- std::swap (Src0, Src1);
1315- Swap = true ;
1316- }
1317-
1318- if (Swap) {
1319- II.setArgOperand (0 , Src0);
1320- II.setArgOperand (1 , Src1);
1321- II.setArgOperand (2 , Src2);
1322- return &II;
1323- }
1324-
1325- // Constant fold umed3 with constant operands.
1326- if (const ConstantInt *C0 = dyn_cast<ConstantInt>(Src0)) {
1327- if (const ConstantInt *C1 = dyn_cast<ConstantInt>(Src1)) {
1328- if (const ConstantInt *C2 = dyn_cast<ConstantInt>(Src2)) {
1329- APInt Result = umed3AMDGCN (C0->getValue (), C1->getValue (), C2->getValue ());
1330- return IC.replaceInstUsesWith (II, ConstantInt::get (II.getType (), Result));
1331- }
1332- }
1333- }
1334-
1335- // Width reduction for integer extensions.
1336- // umed3((zext X), (zext Y), (zext Z)) -> zext (umed3(X, Y, Z))
1337- if (Value *X = matchZExtFromI16 (Src0)) {
1338- if (Value *Y = matchZExtFromI16 (Src1)) {
1339- if (Value *Z = matchZExtFromI16 (Src2)) {
1340- Value *NewCall = IC.Builder .CreateIntrinsic (
1341- IID, {X->getType ()}, {X, Y, Z}, &II, II.getName ());
1342- return new ZExtInst (NewCall, II.getType ());
1343- }
1344- }
1345- }
1346-
1347- break ;
1348- }
13491177 case Intrinsic::amdgcn_icmp:
13501178 case Intrinsic::amdgcn_fcmp: {
13511179 const ConstantInt *CC = cast<ConstantInt>(II.getArgOperand (2 ));
0 commit comments