Equivalent GEP indices with different types are treated as different
indices altogether, leading to a loss in AA precision. Fix the issue
(PR27418) by comparing indices based on their values.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Good catch; scary bug! The test is somewhat brittle though. What do you think of boiling it down to its essence; something like:
; PR27418 - Treat GEP indices with the same value but different types the same ; CHECK-LABEL: test_different_index_types ; CHECK: MustAlias: i16* %tmp1, i16* %tmp2 define void @test_different_index_types([2 x i16]* %arr) { %tmp1 = getelementptr [2 x i16], [2 x i16]* %arr, i16 0, i32 1 %tmp2 = getelementptr [2 x i16], [2 x i16]* %arr, i16 0, i16 1 ret void }
in struct-geps.ll ? Looks like that actually used to return NoAlias (because of the assumption that C1 && C2 implies C1 != C2 later on).
Great! We've done a fix like this locally to get around the problem and it's worked so far.
However, I'm a little bit worried that there could be other places in AA where GEPs are considered to be noaliasing only based on checking Value pointers, e.g in
bool BasicAAResult::isValueEqualInPotentialCycles(const Value *V,
const Value *V2) { if (V != V2) return false;
but I don't know the code well enough to know if the code above can cause any similar problems or not.
You're absolutely right that this problem could lurk elsewhere; isValueEqualInPotentialCycles was actually added to avoid that problem in r198290, for PHI cycles though. I think the same problem could occur for no-op instructions ("alias((add x, 0), x)"), but it looks like all the current users are safe. I'm not sure I have an answer to the general problem though :/
Re: this particular issue though: LGTM, thanks Vedant!