[PATCH] D150838: [SimplifyCFG] add nuw/nsw on BuildLookuptable BitMap shiftwidth calculation

Kohei Asano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 17 21:35:35 PDT 2023


khei4 created this revision.
khei4 added reviewers: nikic, shawnl.
Herald added subscribers: hoy, StephenFan, hiraditya.
Herald added a project: All.
khei4 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

When converting the switch to BitMap lookup table, its shift amount calculation is guaranteed to never overflow when deciding to use BitMap, on WouldFitInRegister <https://github.com/llvm/llvm-project/blob/fbaa086e1b67902082630228bc33890ccd5480ad/llvm/lib/Transforms/Utils/SimplifyCFG.cpp#L6164-L6177>.

This is part of https://reviews.llvm.org/D146903.


https://reviews.llvm.org/D150838

Files:
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp


Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -6129,10 +6129,14 @@
     // truncating it to the width of the bitmask is safe.
     Value *ShiftAmt = Builder.CreateZExtOrTrunc(Index, MapTy, "switch.cast");
 
-    // Multiply the shift amount by the element width.
+    // Multiply the shift amount by the element width. NUW/NSW can always be
+    // set, because WouldFitInRegister guarantees Index * ShiftAmt is in
+    // BitMap's bit width.
     ShiftAmt = Builder.CreateMul(
         ShiftAmt, ConstantInt::get(MapTy, BitMapElementTy->getBitWidth()),
-        "switch.shiftamt");
+        "switch.shiftamt",
+        /*HasNUW =*/true,
+        /*HasNSW =*/true);
 
     // Shift down.
     Value *DownShifted =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150838.523254.patch
Type: text/x-patch
Size: 880 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230518/8cb953e4/attachment.bin>


More information about the llvm-commits mailing list