[llvm] c9fad20 - [InstCombine] Call simplifyInsertValueInst()
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 16 00:51:48 PST 2023
Author: Nikita Popov
Date: 2023-02-16T09:51:40+01:00
New Revision: c9fad20f6a6641249b303df9921771d0481bae7d
URL: https://github.com/llvm/llvm-project/commit/c9fad20f6a6641249b303df9921771d0481bae7d
DIFF: https://github.com/llvm/llvm-project/commit/c9fad20f6a6641249b303df9921771d0481bae7d.diff
LOG: [InstCombine] Call simplifyInsertValueInst()
InstCombine is supposed to be a superset of InstSimplify, but we
were not attempting simplification of insertvalue instructions.
As the test change illustrates, we failed to remove some aggregate
construction patterns because of that.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
llvm/test/Transforms/InstCombine/aggregate-reconstruction.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index 401bcf2ef7157..3ad6b87b7e46c 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -1129,6 +1129,11 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse(
/// It should be transformed to:
/// %0 = insertvalue { i8, i32 } undef, i8 %y, 0
Instruction *InstCombinerImpl::visitInsertValueInst(InsertValueInst &I) {
+ if (Value *V = simplifyInsertValueInst(
+ I.getAggregateOperand(), I.getInsertedValueOperand(), I.getIndices(),
+ SQ.getWithInstruction(&I)))
+ return replaceInstUsesWith(I, V);
+
bool IsRedundant = false;
ArrayRef<unsigned int> FirstIndices = I.getIndices();
diff --git a/llvm/test/Transforms/InstCombine/aggregate-reconstruction.ll b/llvm/test/Transforms/InstCombine/aggregate-reconstruction.ll
index af11aac361bc8..cb7c0dee9feb4 100644
--- a/llvm/test/Transforms/InstCombine/aggregate-reconstruction.ll
+++ b/llvm/test/Transforms/InstCombine/aggregate-reconstruction.ll
@@ -305,13 +305,7 @@ end:
; Like test2 but with a poison base.
define [3 x i32] @poison_base([3 x i32] %srcagg) {
; CHECK-LABEL: @poison_base(
-; CHECK-NEXT: [[I0:%.*]] = extractvalue [3 x i32] [[SRCAGG:%.*]], 0
-; CHECK-NEXT: [[I1:%.*]] = extractvalue [3 x i32] [[SRCAGG]], 1
-; CHECK-NEXT: [[I2:%.*]] = extractvalue [3 x i32] [[SRCAGG]], 2
-; CHECK-NEXT: [[I3:%.*]] = insertvalue [3 x i32] poison, i32 [[I0]], 0
-; CHECK-NEXT: [[I4:%.*]] = insertvalue [3 x i32] [[I3]], i32 [[I1]], 1
-; CHECK-NEXT: [[I5:%.*]] = insertvalue [3 x i32] [[I4]], i32 [[I2]], 2
-; CHECK-NEXT: ret [3 x i32] [[I5]]
+; CHECK-NEXT: ret [3 x i32] [[SRCAGG:%.*]]
;
%i0 = extractvalue [3 x i32] %srcagg, 0
%i1 = extractvalue [3 x i32] %srcagg, 1
More information about the llvm-commits
mailing list