OSDN Git Service

[ConstantRange] Remove costly udivrem from ConstantRange::truncate
authorCraig Topper <craig.topper@gmail.com>
Mon, 5 Jun 2017 20:48:05 +0000 (20:48 +0000)
committerCraig Topper <craig.topper@gmail.com>
Mon, 5 Jun 2017 20:48:05 +0000 (20:48 +0000)
commit13053afeb5687e9fa85f89020374572a712edb12
tree2d2b464db641810afb89d3d1c58b69fe88bb6e01
parentcc713d1bdd34dd8a0ad7ca5ad7f0dea68678b180
[ConstantRange] Remove costly udivrem from ConstantRange::truncate

Truncate currently uses a udivrem call which is going to be slow particularly for larger than 64-bit widths.

As far as I can tell all we were trying to do was modulo LowerDiv by (MaxValue+1) and make sure whatever value was effectively subtracted from LowerDiv was also subtracted from UpperDiv.

This patch recognizes that MaxValue+1 is a power of 2 so we can just use a bitwise AND to accomplish a modulo operation or isolate the upper bits.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304733 91177308-0d34-0410-b5e6-96231b3b80d8
lib/IR/ConstantRange.cpp