[PATCH] D151208: [KnownBits] Add support for nuw/nsw on shifts

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 24 09:54:54 PDT 2023

goldstein.w.n accepted this revision.
goldstein.w.n added a comment.
This revision is now accepted and ready to land.


Comment at: llvm/lib/Support/KnownBits.cpp:255
+  // All shift amounts may result in poison.
+  if (Known.hasConflict())
+    Known.setAllZero();
This should only ever occur if NUW or NSW right? Maybe assert that?

Comment at: llvm/lib/Support/KnownBits.cpp:227
   // possible shifts.
   APInt MaxShiftAmount = RHS.getMaxValue();
+  if (!LHS.isUnknown() || (NUW && NSW)) {
nikic wrote:
> goldstein.w.n wrote:
> > in the NSW/NUW we should be able to further bound MaxShiftAmount with LHS.countLeadingZeros no? (and poison if MinShiftAmunt > LHS.countLeadingZeros)
> Yes, but this is already implicitly handled by the loop below. It stops once it gets the first shift amount that results in poison due to nuw/nsw.
Ah, fair enough.



More information about the llvm-commits mailing list