Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,13 @@ static Type getInsertExtractValueElementType(Type llvmType,
}

OpFoldResult LLVM::ExtractValueOp::fold(FoldAdaptor adaptor) {
if (auto extractValueOp = getContainer().getDefiningOp<ExtractValueOp>()) {
SmallVector<int64_t, 1> newPos(extractValueOp.getPosition());
newPos.append(getPosition().begin(), getPosition().end());
setPosition(newPos);
getContainerMutable().set(extractValueOp.getContainer());
return getResult();
}
auto insertValueOp = getContainer().getDefiningOp<InsertValueOp>();
OpFoldResult result = {};
while (insertValueOp) {
Expand Down
10 changes: 10 additions & 0 deletions mlir/test/Dialect/LLVMIR/canonicalize.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ llvm.func @fold_unrelated_extractvalue(%arr: !llvm.array<4 x f32>) -> f32 {
llvm.return %3 : f32
}

// -----
// CHECK-LABEL: fold_extract_extractvalue
llvm.func @fold_extract_extractvalue(%arr: !llvm.struct<(i64, array<1 x ptr<1>>)>) -> !llvm.ptr<1> {
// CHECK: llvm.extractvalue %{{.*}}[1, 0]
// CHECK-NOT: extractvalue
%a = llvm.extractvalue %arr[1] : !llvm.struct<(i64, array<1 x ptr<1>>)>
%b = llvm.extractvalue %a[0] : !llvm.array<1 x ptr<1>>
llvm.return %b : !llvm.ptr<1>
}

// -----

// CHECK-LABEL: fold_bitcast
Expand Down
Loading