]> granicus.if.org Git - llvm/commit
[InstCombine] Resubmit the combine of A->B->A BitCast and fix for pr27996
authorGuozhi Wei <carrot@google.com>
Tue, 25 Oct 2016 20:43:42 +0000 (20:43 +0000)
committerGuozhi Wei <carrot@google.com>
Tue, 25 Oct 2016 20:43:42 +0000 (20:43 +0000)
commit413fdf3b7f25bce26d8e585acafba53da8bc5f6a
tree11f8ae1160537db2850360109b6c52a9a75c2bfc
parent09845fdead5e1f6641fb55a4fb7f1aa4c1a3b46b
[InstCombine] Resubmit the combine of A->B->A BitCast and fix for pr27996

The original patch of the A->B->A BitCast optimization was reverted by r274094 because it may cause infinite loop inside compiler https://llvm.org/bugs/show_bug.cgi?id=27996.

The problem is with following code

xB = load (type B);
xA = load (type A);
+yA = (A)xB; B -> A
+zAn = PHI[yA, xA]; PHI
+zBn = (B)zAn; // A -> B
store zAn;
store zBn;

optimizeBitCastFromPhi generates

+zBn = (B)zAn; // A -> B

and expects it will be combined with the following store instruction to another

store zAn

Unfortunately before combineStoreToValueType is called on the store instruction, optimizeBitCastFromPhi is called on the new BitCast again, and this pattern repeats indefinitely.

optimizeBitCastFromPhi only generates BitCast for load/store instructions, only the BitCast before store can cause the reexecution of optimizeBitCastFromPhi, and BitCast before store can easily be handled by InstCombineLoadStoreAlloca.cpp. So the solution to the problem is if all users of a CI are store instructions, we should not do optimizeBitCastFromPhi on it. Then optimizeBitCastFromPhi will not be called on the new BitCast instructions.

Differential Revision: https://reviews.llvm.org/D23896

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285116 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineCasts.cpp
lib/Transforms/InstCombine/InstCombineInternal.h
test/Transforms/InstCombine/pr25342.ll [new file with mode: 0644]
test/Transforms/InstCombine/pr27703.ll [new file with mode: 0644]
test/Transforms/InstCombine/pr27996.ll [new file with mode: 0644]