[PATCH] D52707: Switch optimization in IR for known maximum switch values

Ayonam Ray via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 2 03:44:51 PDT 2018


ayonam added a comment.

In https://reviews.llvm.org/D52707#1251513, @efriedma wrote:

> The yellow bars are just Phabricator noting copy-pasted code; if you hover over the bar, you can get more details from the tooltip.  You might not have to do anything about it in general, but in this case I think it's worth refactoring.


Thanks.  I will refactor the second block of code since the first block has one additional operation of storing the PHIs in a vector.

As for the other comment in the code:

countMaxTrailingOnes will not exceed the number of bits in the switch expression type (local variable ValueWidth above).  But then the '1' should probably be '1LL' and MaxSwitchValue should be of type 'long long' to ensure that all possible value widths are taken care of.



================
Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:4859
+         ValueWidth)
+    MaxSwitchValue = (1 << Known.countMaxTrailingOnes()) - 1;
+
----------------
efriedma wrote:
> Can this shift overflow?
countMaxTrailingOnes will not exceed the number of bits in the switch expression type (local variable ValueWidth above).  But then the '1' should probably be '1LL' and MaxSwitchValue should be of type 'long long' to ensure that all possible value widths are taken care of.


Repository:
  rL LLVM

https://reviews.llvm.org/D52707





More information about the llvm-commits mailing list