[llvm] df4e0be - [NFC][ConstantFold] Check getAggregateElement before getSplatValue call
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 3 21:52:23 PDT 2021
Author: Senran Zhang
Date: 2021-08-03T21:52:14-07:00
New Revision: df4e0beaeb0cba052e51094ff8d9447bea11fe62
URL: https://github.com/llvm/llvm-project/commit/df4e0beaeb0cba052e51094ff8d9447bea11fe62
DIFF: https://github.com/llvm/llvm-project/commit/df4e0beaeb0cba052e51094ff8d9447bea11fe62.diff
LOG: [NFC][ConstantFold] Check getAggregateElement before getSplatValue call
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.
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D107252
Added:
Modified:
llvm/lib/IR/ConstantFold.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index e1e28d1230b0e..173117185f2af 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -667,13 +667,16 @@ Constant *llvm::ConstantFoldExtractElementInstruction(Constant *Val,
}
}
+ 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,
More information about the llvm-commits
mailing list