[PATCH] D49958: [MISC]Fix wrong usage of std::equal()

ChenZheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 28 07:03:48 PDT 2018


shchenz created this revision.
shchenz added reviewers: spatel, lebedev.ri, nemanjai.
Herald added a subscriber: hiraditya.

This is a small patch to fix std::equal() wrong usage.

Firstly find this issue in function visitSelect() of file SelectionDAGBuilder.cpp:

  // Min/max matching is only viable if all output VTs are the same.
  if (std::equal(ValueVTs.begin(), ValueVTs.end(), ValueVTs.begin())) {

This is obviously wrong. "std::equal(ValueVTs.begin(), ValueVTs.end(), ValueVTs.begin())" is already true.

Then I go through all llvm codes, find another two wrong places.

Since this is a very obviously wrong mistake and related to c++ language not to compiler area, I do not add some cases for this. Hope it is ok.


https://reviews.llvm.org/D49958

Files:
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/Transforms/Scalar/NewGVN.cpp


Index: llvm/lib/Transforms/Scalar/NewGVN.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/NewGVN.cpp
+++ llvm/lib/Transforms/Scalar/NewGVN.cpp
@@ -3176,8 +3176,8 @@
             std::back_inserter(OperandList));
   bool Okay = OperandList.size() == 1;
   if (!Okay)
-    Okay =
-        std::equal(OperandList.begin(), OperandList.end(), OperandList.begin());
+    Okay = std::equal(OperandList.begin() + 1, OperandList.end(),
+                      OperandList.begin());
   if (Okay)
     return singleReachablePHIPath(Visited, cast<MemoryAccess>(OperandList[0]),
                                   Second);
@@ -3272,8 +3272,9 @@
                        const MemoryDef *MD = cast<MemoryDef>(U);
                        return ValueToClass.lookup(MD->getMemoryInst());
                      });
-      assert(std::equal(PhiOpClasses.begin(), PhiOpClasses.end(),
-                        PhiOpClasses.begin()) &&
+      assert((PhiOpClasses.size() == 1 ||
+              std::equal(PhiOpClasses.begin() + 1, PhiOpClasses.end(),
+                         PhiOpClasses.begin())) &&
              "All MemoryPhi arguments should be in the same class");
     }
   }
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -2916,7 +2916,8 @@
     ISD::VSELECT : ISD::SELECT;
 
   // Min/max matching is only viable if all output VTs are the same.
-  if (std::equal(ValueVTs.begin(), ValueVTs.end(), ValueVTs.begin())) {
+  if (ValueVTs.size() == 1 ||
+      std::equal(ValueVTs.begin() + 1, ValueVTs.end(), ValueVTs.begin())) {
     EVT VT = ValueVTs[0];
     LLVMContext &Ctx = *DAG.getContext();
     auto &TLI = DAG.getTargetLoweringInfo();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49958.157854.patch
Type: text/x-patch
Size: 1885 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180728/363f28bd/attachment.bin>


More information about the llvm-commits mailing list