@@ -1128,20 +1128,19 @@ void State::addInfoFor(BasicBlock &BB) {
1128
1128
FactOrCheck::getCheck (DT.getNode (&BB), cast<CallInst>(&I)));
1129
1129
break ;
1130
1130
// Enqueue the intrinsics to add extra info.
1131
+ case Intrinsic::abs:
1131
1132
case Intrinsic::umin:
1132
1133
case Intrinsic::umax:
1133
1134
case Intrinsic::smin:
1134
1135
case Intrinsic::smax:
1135
1136
case Intrinsic::usub_sat:
1136
- // TODO: handle llvm.abs as well
1137
1137
WorkList.push_back (
1138
1138
FactOrCheck::getCheck (DT.getNode (&BB), cast<CallInst>(&I)));
1139
1139
// TODO: Check if it is possible to instead only added the min/max facts
1140
1140
// when simplifying uses of the min/max intrinsics.
1141
1141
if (!isGuaranteedNotToBePoison (&I))
1142
1142
break ;
1143
1143
[[fallthrough]];
1144
- case Intrinsic::abs:
1145
1144
case Intrinsic::uadd_sat:
1146
1145
WorkList.push_back (FactOrCheck::getInstFact (DT.getNode (&BB), &I));
1147
1146
break ;
@@ -1537,6 +1536,28 @@ static bool checkAndReplaceUSubSat(SaturatingInst *I, ConstraintInfo &Info,
1537
1536
return false ;
1538
1537
}
1539
1538
1539
+ static bool checkAndReplaceAbs (IntrinsicInst *I, ConstraintInfo &Info,
1540
+ SmallVectorImpl<Instruction *> &ToRemove) {
1541
+ assert (I->getIntrinsicID () == Intrinsic::abs && " Expected abs intrinsic" );
1542
+ Value *Op = I->getOperand (0 );
1543
+ if (checkCondition (ICmpInst::ICMP_SGE, Op, ConstantInt::get (Op->getType (), 0 ),
1544
+ I, Info)
1545
+ .value_or (false )) {
1546
+ I->replaceAllUsesWith (Op);
1547
+ ToRemove.push_back (I);
1548
+ return true ;
1549
+ }
1550
+ if (checkCondition (ICmpInst::ICMP_SLT, Op, ConstantInt::get (Op->getType (), 0 ),
1551
+ I, Info)
1552
+ .value_or (false )) {
1553
+ IRBuilder<> Builder (I->getParent (), I->getIterator ());
1554
+ I->replaceAllUsesWith (Builder.CreateNeg (Op));
1555
+ ToRemove.push_back (I);
1556
+ return true ;
1557
+ }
1558
+ return false ;
1559
+ }
1560
+
1540
1561
static void
1541
1562
removeEntryFromStack (const StackEntry &E, ConstraintInfo &Info,
1542
1563
Module *ReproducerModule,
@@ -1863,6 +1884,10 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT, LoopInfo &LI,
1863
1884
Changed |= checkAndReplaceUSubSat (SatIntr, Info, ToRemove);
1864
1885
else
1865
1886
llvm_unreachable (" Unexpected intrinsic." );
1887
+ } else if (auto *II = dyn_cast<IntrinsicInst>(Inst)) {
1888
+ if (II->getIntrinsicID () == Intrinsic::abs) {
1889
+ Changed |= checkAndReplaceAbs (II, Info, ToRemove);
1890
+ }
1866
1891
}
1867
1892
continue ;
1868
1893
}
0 commit comments