[PATCH] D15857: [InstCombine] Defend against worst-case exponential execution time

James Molloy via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 6 05:17:30 PST 2016


jmolloy updated this revision to Diff 44108.
jmolloy added a comment.

Hi David, Joerg,

This version rewrites the algorithm significantly. In the original algorithm every recursive call was a function of a Value* and multiple other operands. This made memoization impossible as it is not often that the collectBitParts is called with the same Value* and also the same BitMask/OverallLeftShift.

collectBitParts is now just a function of a single Value*, and it is up to the caller to apply any transformations on its result. This means the result can be memoized which means that Joerg's testcase requires ~64 recursions instead of 2^32. The new design makes the code smaller and more concise too.

David, I have implemented this in InstCombine still. I also have a version of this patch implemented in CodeGenPrepare. The CGP patch cannot fold bitreverse(bitreverse(X)) -> X, but perhaps that pattern is less common than the equivalent with bswap.

I am happy to switch to the CGP version if you wish, which would mean I'd revert all of my patches to InstCombineAndOrXor.cpp.

Cheers,

James


Repository:
  rL LLVM

http://reviews.llvm.org/D15857

Files:
  lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
  test/Transforms/InstCombine/bitreverse-hang.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15857.44108.patch
Type: text/x-patch
Size: 13315 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160106/50d8354a/attachment.bin>


More information about the llvm-commits mailing list