[PATCH] D107252: [NFC][ConstantFold] Check getAggregateElement before getSplatValue call

Senran Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 2 01:43:37 PDT 2021


zsrkmyn created this revision.
zsrkmyn added reviewers: majnemer, MaskRay, CarolineConcatto.
Herald added subscribers: dexonsmith, hiraditya.
zsrkmyn requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Constant::getSplatValue has O(N) time complexity in the worst case,
where N is the # of elements in a vector. So we call
Constant::getAggregateElement first and return earlier if possible to
avoid unnecessary getSplatValue calls.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107252

Files:
  llvm/lib/IR/ConstantFold.cpp


Index: llvm/lib/IR/ConstantFold.cpp
===================================================================
--- llvm/lib/IR/ConstantFold.cpp
+++ llvm/lib/IR/ConstantFold.cpp
@@ -667,13 +667,16 @@
     }
   }
 
+  if (Constant *C = Val->getAggregateElement(CIdx))
+    return C;
+
   // Lane < Splat minimum vector width => extractelt Splat(x), Lane -> x
   if (CIdx->getValue().ult(ValVTy->getElementCount().getKnownMinValue())) {
     if (Constant *SplatVal = Val->getSplatValue())
       return SplatVal;
   }
 
-  return Val->getAggregateElement(CIdx);
+  return nullptr;
 }
 
 Constant *llvm::ConstantFoldInsertElementInstruction(Constant *Val,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107252.363394.patch
Type: text/x-patch
Size: 645 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210802/047e9328/attachment.bin>


More information about the llvm-commits mailing list