@@ -865,11 +865,15 @@ void State::addInfoFor(BasicBlock &BB) {
865
865
namespace {
866
866
// / Helper to keep track of a condition and if it should be treated as negated
867
867
// / for reproducer construction.
868
+ // / Pred == Predicate::BAD_ICMP_PREDICATE indicates that this entry is a
869
+ // / placeholder to keep the ReproducerCondStack in sync with DFSInStack.
868
870
struct ReproducerEntry {
869
- CmpInst *Cond;
870
- bool IsNot;
871
+ ICmpInst::Predicate Pred;
872
+ Value *LHS;
873
+ Value *RHS;
871
874
872
- ReproducerEntry (CmpInst *Cond, bool IsNot) : Cond(Cond), IsNot(IsNot) {}
875
+ ReproducerEntry (ICmpInst::Predicate Pred, Value *LHS, Value *RHS)
876
+ : Pred(Pred), LHS(LHS), RHS(RHS) {}
873
877
};
874
878
} // namespace
875
879
@@ -898,13 +902,9 @@ static void generateReproducer(CmpInst *Cond, Module *M,
898
902
// ConstraintElimination can decompose. Such values will be considered as
899
903
// external inputs to the reproducer, they are collected and added as function
900
904
// arguments later.
901
- auto CollectArguments = [&](CmpInst *Cond) {
902
- if (!Cond)
903
- return ;
904
- auto &Value2Index =
905
- Info.getValue2Index (CmpInst::isSigned (Cond->getPredicate ()));
906
- SmallVector<Value *, 4 > WorkList;
907
- WorkList.push_back (Cond);
905
+ auto CollectArguments = [&](ArrayRef<Value *> Ops, bool IsSigned) {
906
+ auto &Value2Index = Info.getValue2Index (IsSigned);
907
+ SmallVector<Value *, 4 > WorkList (Ops);
908
908
while (!WorkList.empty ()) {
909
909
Value *V = WorkList.pop_back_val ();
910
910
if (!Seen.insert (V).second )
@@ -927,8 +927,9 @@ static void generateReproducer(CmpInst *Cond, Module *M,
927
927
};
928
928
929
929
for (auto &Entry : Stack)
930
- CollectArguments (Entry.Cond );
931
- CollectArguments (Cond);
930
+ if (Entry.Pred != ICmpInst::BAD_ICMP_PREDICATE)
931
+ CollectArguments ({Entry.LHS , Entry.RHS }, ICmpInst::isSigned (Entry.Pred ));
932
+ CollectArguments (Cond, ICmpInst::isSigned (Cond->getPredicate ()));
932
933
933
934
SmallVector<Type *> ParamTys;
934
935
for (auto *P : Args)
@@ -990,19 +991,16 @@ static void generateReproducer(CmpInst *Cond, Module *M,
990
991
// function. Then add an ICmp for the condition (with the inverse predicate if
991
992
// the entry is negated) and an assert using the ICmp.
992
993
for (auto &Entry : Stack) {
993
- if (! Entry.Cond )
994
+ if (Entry.Pred == ICmpInst::BAD_ICMP_PREDICATE )
994
995
continue ;
995
996
996
- LLVM_DEBUG (dbgs () << " Materializing assumption " << *Entry.Cond << " \n " );
997
- CmpInst::Predicate Pred = Entry.Cond ->getPredicate ();
998
- if (Entry.IsNot )
999
- Pred = CmpInst::getInversePredicate (Pred);
1000
-
1001
- CloneInstructions ({Entry.Cond ->getOperand (0 ), Entry.Cond ->getOperand (1 )},
1002
- CmpInst::isSigned (Entry.Cond ->getPredicate ()));
997
+ LLVM_DEBUG (
998
+ dbgs () << " Materializing assumption icmp " << Entry.Pred << ' ' ;
999
+ Entry.LHS ->printAsOperand (dbgs (), /* PrintType=*/ true ); dbgs () << " , " ;
1000
+ Entry.RHS ->printAsOperand (dbgs (), /* PrintType=*/ false ); dbgs () << " \n " );
1001
+ CloneInstructions ({Entry.LHS , Entry.RHS }, CmpInst::isSigned (Entry.Pred ));
1003
1002
1004
- auto *Cmp = Builder.CreateICmp (Pred, Entry.Cond ->getOperand (0 ),
1005
- Entry.Cond ->getOperand (1 ));
1003
+ auto *Cmp = Builder.CreateICmp (Entry.Pred , Entry.LHS , Entry.RHS );
1006
1004
Builder.CreateAssumption (Cmp);
1007
1005
}
1008
1006
@@ -1383,7 +1381,7 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT,
1383
1381
1384
1382
Info.addFact (Pred, A, B, CB.NumIn , CB.NumOut , DFSInStack);
1385
1383
if (ReproducerModule && DFSInStack.size () > ReproducerCondStack.size ())
1386
- ReproducerCondStack.emplace_back (cast<CmpInst>(Cmp), CB. Not );
1384
+ ReproducerCondStack.emplace_back (Pred, A, B );
1387
1385
1388
1386
Info.transferToOtherSystem (Pred, A, B, CB.NumIn , CB.NumOut , DFSInStack);
1389
1387
if (ReproducerModule && DFSInStack.size () > ReproducerCondStack.size ()) {
@@ -1392,7 +1390,8 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT,
1392
1390
for (unsigned I = 0 ,
1393
1391
E = (DFSInStack.size () - ReproducerCondStack.size ());
1394
1392
I < E; ++I) {
1395
- ReproducerCondStack.emplace_back (nullptr , false );
1393
+ ReproducerCondStack.emplace_back (ICmpInst::BAD_ICMP_PREDICATE,
1394
+ nullptr , nullptr );
1396
1395
}
1397
1396
}
1398
1397
}
0 commit comments