diff options
author | Arthur Eubanks <aeubanks@google.com> | 2020-08-10 12:53:30 -0700 |
---|---|---|
committer | Arthur Eubanks <aeubanks@google.com> | 2020-08-13 15:59:17 -0700 |
commit | 41f49736a9a06650d9d4f1ada21d051585ab7bbe (patch) | |
tree | b5c6c5ebcd797b95fd97e00c983f2eeba44fb9e6 /llvm/lib/IR/ConstantFold.cpp | |
parent | ae6523cd62a44642390f4f9d9ba9ce17d5bbbc58 (diff) | |
download | llvm-41f49736a9a06650d9d4f1ada21d051585ab7bbe.zip llvm-41f49736a9a06650d9d4f1ada21d051585ab7bbe.tar.gz llvm-41f49736a9a06650d9d4f1ada21d051585ab7bbe.tar.bz2 |
[ConstProp] Handle insertelement constants
Previously ConstantFoldExtractElementInstruction() would only work with
insertelement instructions, not contants. This properly handles
insertelement constants as well.
Reviewed By: efriedma
Differential Revision: https://reviews.llvm.org/D85865
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index f02246c..2d3afca 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -853,6 +853,15 @@ Constant *llvm::ConstantFoldExtractElementInstruction(Constant *Val, } return CE->getWithOperands(Ops, ValVTy->getElementType(), false, Ops[0]->getType()->getPointerElementType()); + } else if (CE->getOpcode() == Instruction::InsertElement) { + if (const auto *IEIdx = dyn_cast<ConstantInt>(CE->getOperand(2))) { + if (APSInt::isSameValue(APSInt(IEIdx->getValue()), + APSInt(CIdx->getValue()))) { + return CE->getOperand(1); + } else { + return ConstantExpr::getExtractElement(CE->getOperand(0), CIdx); + } + } } } |