[PATCH] D85865: [ConstProp] Handle insertelement constants
Arthur Eubanks via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 12 18:16:55 PDT 2020
aeubanks updated this revision to Diff 285232.
aeubanks added a comment.
Move code to ConstantFoldExtractElementInstruction()
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85865/new/
https://reviews.llvm.org/D85865
Files:
llvm/lib/IR/ConstantFold.cpp
llvm/test/Transforms/InstSimplify/vscale.ll
Index: llvm/test/Transforms/InstSimplify/vscale.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/vscale.ll
+++ llvm/test/Transforms/InstSimplify/vscale.ll
@@ -95,6 +95,14 @@
ret i32 %r
}
+define i32 @insert_extract_element_same_vec_idx_3() {
+; CHECK-LABEL: @insert_extract_element_same_vec_idx_3(
+; CHECK-NEXT: ret i32 1
+;
+ %r = extractelement <vscale x 4 x i32> insertelement (<vscale x 4 x i32> undef, i32 1, i64 4), i64 4
+ ret i32 %r
+}
+
; more complicated expressions
define <vscale x 2 x i1> @cmp_le_smax_always_true(<vscale x 2 x i64> %x) {
Index: llvm/lib/IR/ConstantFold.cpp
===================================================================
--- llvm/lib/IR/ConstantFold.cpp
+++ llvm/lib/IR/ConstantFold.cpp
@@ -853,6 +853,13 @@
}
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 (IEIdx->equalsInt(CIdx->getZExtValue())) {
+ if (auto *IEValue = dyn_cast<Constant>(CE->getOperand(1)))
+ return IEValue;
+ }
+ }
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85865.285232.patch
Type: text/x-patch
Size: 1307 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200813/e3dbf866/attachment.bin>
More information about the llvm-commits
mailing list