[ScalarEvolution] Iteration order over Set depends on pointer values
| Bugzilla Link | 26816 |
| Resolution | INVALID |
| Resolved on | Mar 03, 2016 03:16 |
| Version | trunk |
| OS | Linux |
| CC | @hfinkel |
Extended Description
I am seeing some non-deterministic behavior in the output files in some tests that I am running.
I have been tracking the problem and I think it is caused by a new for loop in ScalarEvolutionExpander. The iteration order over Set below will depend on pointer values. I am not sure how to fix this.
Value *SCEVExpander::FindValueInExprValueMap(const SCEV *S, const Instruction *InsertPt) { SetVector<Value *> *Set = SE.getSCEVValues(S); // If the expansion is not in CanonicalMode, and the SCEV contains any // sub scAddRecExpr type SCEV, it is required to expand the SCEV literally. if (CanonicalMode || !SE.containsAddRecurrence(S)) { // If S is scConstant, it may be worse to reuse an existing Value. if (S->getSCEVType() != scConstant && Set) { // Choose a Value from the set which dominates the insertPt. // insertPt should be inside the Value's parent loop so as not to break // the LCSSA form. for (auto const &Ent : *Set) {
I am not able to reproduce the non-determinism on trunk.
Closing this issue because it is based on my bad assumption on SetVector.
For a SetVector, the order of iteration is guaranteed to match the order of insertion into the SetVector, so it shouldn't be affected by the pointer values.
Oh, I see! My mistake, I just assumed it worked like std::vector.
Could you provide a testcase to show the problem?
It's tricky. I have two opt-binaries that I run on the same input with different output. Example of diff in output:
@@ -10,9 +10,9 @@ br label %bb2.outer
bb2.outer: ; preds = %bb6, %0
- %indvar = phi i16 [ %indvar.next, %bb6 ], [ 0, %0 ]
- %indvar7 = phi i16 [ %indvar.next8, %bb6 ], [ 0, %0 ] %d.1.0.ph = phi i16 [ %_tmp5, %bb6 ], [ undef, %0 ]
- %1 = mul i16 %indvar, -1
- %1 = mul i16 %indvar7, -1
There is no functional difference; only the naming.
I will experiment a while and see if I can create a test case that makes sense.
For a SetVector, the order of iteration is guaranteed to match the order of insertion into the SetVector, so it shouldn't be affected by the pointer values.
Could you provide a testcase to show the problem?