Skip to content

Commit

Permalink
[InstCombine] Call simplifyInsertValueInst()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic committed Feb 16, 2023
1 parent 6bec2c3 commit c9fad20
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 5 additions & 0 deletions llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
Expand Up @@ -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();

Expand Down
8 changes: 1 addition & 7 deletions llvm/test/Transforms/InstCombine/aggregate-reconstruction.ll
Expand Up @@ -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
Expand Down

0 comments on commit c9fad20

Please sign in to comment.