-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BasicAA bug #18442
Comments
Here is a first analysis of the issue. The relevant part of the IR is shown below, with some instruction prefixed for reference in the analysis. ... codeRepl: ; preds = %for.body, %entry for.body: ; preds = %codeRepl A is (wrongly) removed by DSE, because it believes B kills it. It does not see that %4 in D may alias with %arrayidx5 in A. BasicAA computes the difference between %arrayidx5 and %arrayidx13 and finds a constant difference, which is not valid as C can (and has !) modified %jj7, which is the index in %oa5. |
Manually reduced testcase |
Thanks for looking at this! Do you see what part of BasicAA is at fault (I guess that BasicAliasAnalysis::aliasPHI is the problem)? |
I more or less see what is at fault. The problem indeed shows up in BasicAliasAnalysis::aliasPHI, but I do not (yet) understand how BasicAA handles loops, and particularly why it does not see that main_for.inc can just do whatever it wants with the pointer. I definitely need help on this. This bugs looks rather serious to me, and it may be the same which is biting us in llvm/llvm-bugzilla-archive#18067 , in another pass, but with a similar code structure. |
Wow this is indeed scary :) … and seems to have been in there for a long long time (I have tested as far back as 3.1, but at least 2.9) define i32 @pr18068(i32* %jj7, i32* %j) #0 { codeRepl: ; preds = %for.body, %entry for.body: ; preds = %codeRepl %idxprom4 = zext i32 %1 to i64 bye: ; preds = %codeRepl As Arnaud correctly observed the root of this problem is that a query for "aliasCheck(%arrayidx5, %arrayidx13)" returns “NoAlias”. This in turn makes the phi “%0” NoAlias "%arrayidx5” because it is believed that So, why do we believe “noalias(%arrayidx5, %arrayidx13)”? When analyze %arrayidx5 = gep %oa, 0, %load %arrayidx13 = gep %oa, 0, (%load - #AConst) aliasGEP() We get a constant difference of #AConst (-4) and a variable difference which is the difference between “%load” and “%load”. Because there are paths (%arrayidx13->back edge->%arrayidx5) under which those two loads are not the same execution of a load it is not safe to assume their value is the same. I.e the logic that when Dest[i] == Src[j] we can simply ignore it is not a valid one: GetIndexDifference(SmallVectorImpl &Dest, for (unsigned i = 0, e = Src.size(); i != e; ++i) {
} Or alternatively we have to start looking at possible paths through the cfg (be a lot more careful at phis). Let me try alternative one and see what that does to llvm test-suite and external (although, I fear badness). |
xref: rdar://15653794 |
The problem really is the evaluation through the phi node: check-alias(%0 = PHI(%j, %array13), %array5) = because of the cycle (we are following %array13 "to the previous iteration") "Value"s don't necessarily imply value equivalence anymore. Maybe an approach where we build a set of phi nodes we have followed and when we check value equivalence we also make sure this value dominates the phis would work ... |
I think that makes sense. I suspect that you'll need a cutoff on the dominance search -- we should try to set this so that we don't regress at least anything in the test suite that this currently catches. |
Fixed in r198290. |
*** Bug llvm/llvm-bugzilla-archive#18067 has been marked as a duplicate of this bug. *** |
Extended Description
ClangBugs2/diff/t43047 from #16805 is a DSE miscompile.
To reproduce:
opt -o o.bc -basicaa -dse bugpoint-tooptimize.bc
clang o.bc bugpoint-tonotoptimize.bc -o t
./t < input.txt
res = 1910
whereas running:
clang bugpoint-tooptimize.bc bugpoint-tonotoptimize.bc -o t
./t < input.txt
res = 2553
The text was updated successfully, but these errors were encountered: