[PATCH] D23896: [InstCombine] Try to resubmit the combine of A->B->A BitCast and fix for pr27996
Guozhi Wei via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 25 16:56:41 PDT 2016
Carrot created this revision.
Carrot added reviewers: majnemer, evstupac.
Carrot added a subscriber: llvm-commits.
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, and BitCast with load/store instructions can easily be handled by InstCombineLoadStoreAlloca.cpp. So the solution to the problem is if all users of a CI are load/store instructions, we should not do optimizeBitCastFromPhi on it. Then optimizeBitCastFromPhi will not be called on the new BitCast instructions.
https://reviews.llvm.org/D23896
Files:
lib/Transforms/InstCombine/InstCombineCasts.cpp
lib/Transforms/InstCombine/InstCombineInternal.h
test/Transforms/InstCombine/pr25342.ll
test/Transforms/InstCombine/pr27703.ll
test/Transforms/InstCombine/pr27996.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23896.69303.patch
Type: text/x-patch
Size: 11521 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160825/72e7519e/attachment-0001.bin>
More information about the llvm-commits
mailing list