[PATCH] D99481: [InstCombine] Fix miscompile on GEP+load to icmp fold (PR45210)
Juneyoung Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 3 01:05:56 PDT 2021
aqjune added a comment.
I investigated a bit and the reason was as follows.
The reason was that `foldCmpLoadFromIndexedGlobal` can simply give up folding load+cmp, causing the new instructions created by these lines to be dummy ones:
if (countTrailingZeros(ElementSize) != 0) {
Value *Mask = ConstantInt::getSigned(Idx->getType(), -1);
Mask = Builder.CreateLShr(Mask, countTrailingZeros(ElementSize));
Idx = Builder.CreateAnd(Idx, Mask);
}
In InstCombine's next iteration, they are found as a dead code. They are removed & InstCombine proceeds to the next iteration because there was something to remove.
Then, `foldCmpLoadFromIndexedGlobal` is called again, creating the dummy instructions, then dead code is removed, and so on.
To avoid this, the lshr+and should be created only when they are necessary.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D99481/new/
https://reviews.llvm.org/D99481
More information about the llvm-commits
mailing list