[PATCH] D76664: [ConstantFold][NFC] Compile time optimization for large vectors
    David Majnemer via Phabricator via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Tue Mar 24 18:03:53 PDT 2020
    
    
  
majnemer added inline comments.
================
Comment at: llvm/include/llvm/IR/Constants.h:771
+  // Cache whether or not the constant is a splat.
+  mutable Optional<bool> IsSplat;
+  bool isSplatData() const;
----------------
You could save a byte by rolling your own optional. I think this is valuable because there may be many `ConstantDataVector`.
Maybe something like:
  bool IsSplatSet : 1;
  bool IsSplat : 1;
================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:177-178
   DemandedLHS = DemandedRHS = APInt::getNullValue(NumElts);
-
+  if (DemandedElts.isNullValue())
+    return true;
+  // Simple case of a shuffle with zeroinitializer.
----------------
ThomasRaoux wrote:
> majnemer wrote:
> > I'd float this to the top before we create more APInts.
> I believe we still need to set DemandedLHS and DemandedRHS to APInt::getNullValue(NumElts) so I cannot really move it up? 
I was just thinking of floating this bit up:
  if (DemandedElts.isNullValue())
    return true;
================
Comment at: llvm/lib/IR/ConstantFold.cpp:1389
+      return UndefValue::get(VTy);
+    if (C1Splat && C2Splat) {
+      return ConstantVector::getSplat(
----------------
Now that these are lazy, maybe only do `C1->getSplatValue()` if C2Splat is true.
================
Comment at: llvm/lib/IR/Constants.cpp:2907
+bool ConstantDataVector::isSplat() const {
+  if(!IsSplat.hasValue())
+    IsSplat = isSplatData();
----------------
Formatting.
CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76664/new/
https://reviews.llvm.org/D76664
    
    
More information about the llvm-commits
mailing list