[PATCH] D151640: [LSV] Attempt to fix comparison of APInt's with different bit widths.

Justin Lebar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 28 22:18:23 PDT 2023


jlebar created this revision.
jlebar added a reviewer: ronlieb.
Herald added a subscriber: hiraditya.
Herald added a project: All.
jlebar requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead.
Herald added a project: LLVM.

I have not been able to make a testcase for this, but this should be safe, and
it may fix the assertion being hit in https://reviews.llvm.org/D151630#4378572.

(We should absolutely figure out a testcase for this, either before or after
this is checked in.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151640

Files:
  llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp


Index: llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
@@ -1295,7 +1295,13 @@
       std::optional<APInt> FalseDiff =
           getConstantOffset(SelectA->getFalseValue(), SelectB->getFalseValue(),
                             ContextInst, Depth);
-      if (TrueDiff == FalseDiff)
+      // A bit unclear how we can get TrueDiff and FalseDiff with different bit
+      // widths, since the bit width returned by getConstantOffset is determined
+      // by the datatype of the pointer, and both sides of the `select` should
+      // have the same datatype.  But we seem to be hitting this in practice.
+      if (FalseDiff.has_value() &&
+          TrueDiff->getBitWidth() == FalseDiff->getBitWidth() &&
+          TrueDiff == FalseDiff)
         return TrueDiff;
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151640.526381.patch
Type: text/x-patch
Size: 969 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230529/a012119f/attachment.bin>


More information about the llvm-commits mailing list