Open Anonymous15592 opened 7 months ago
Hi!
This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:
test/
create fine-grained testing targets, so you can e.g. use make check-clang-ast
to only run Clang's AST tests.git clang-format HEAD~1
to format your changes.If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.
@llvm/issue-subscribers-good-first-issue
Author: anonymousMCS (anonymousMCS)
@joker-eph I would try to take a stab at this issue. As I am totally new could you guide as to which areas of the code i should be looking into or any insight you may have on the issue?
Thank you!
@joker-eph Could you give a comprehensive description of the issue here that can get me going?
Seems like this is a mishandling in InsertOpConstantFolder, I would try to build a debug build of MLIR and run this with a debugger (or add print statement around the crash)
Hello @joker-eph,
I'm currently investigating an issue using LLDB and could benefit from your expertise to help me navigate through it.
During my investigation, I used LLDB to examine the types of intAttr and eltType:
(lldb) expression intAttr.getType().dump() index (lldb) expression eltType.dump() i64
Subsequently, I noticed a discrepancy in the output of allValues[0].dump() before and after a copy operation:
(lldb) expr allValues[0].dump() 1526248407 : i64
After the copy operation:
(lldb) expr allValues[0].dump() 1 : index
I believe the issue may be related to the following code segment:
`
SmallVector
auto allValues = llvm::to_vector(denseDest.getValues
Could you please provide me with some guidance or hints on how to further investigate and resolve this issue?
Thank you for your time and assistance.
%1 = llvm.mlir.constant(1 : index) : i64
is a constant where the SSA value type is i64 but the attribute is 1 : index
.
The %101 = vector.insert %1, %cst_7 [0] : i64
is basically replacing the vector with the provided value, the folding op needs to return an attribute modeling this new constant. However it likely just takes the 1 : index
as-is while the expected type of the produced attribue should be i64
.
@joker-eph, I've been trying to locate where the actual folding operations happen in the MLIR codebase, but I've only found the starting point for folding operations:
LogicalResult result = op->fold(/*operands=*/std::nullopt, foldedOp);
Could you please clarify where the folding operations are actually performed in the MLIR codebase?
It is in the backtrace in the original description:
#7 0x0000560afa0dc621 mlir::DenseElementsAttr::get(mlir::ShapedType, llvm::ArrayRef<mlir::Attribute>) (/data/bin/llvm-project/build/bin/mlir-opt+0x441e621)
#8 0x0000560af93c28b6 (anonymous namespace)::InsertOpConstantFolder::matchAndRewrite(mlir::vector::InsertOp, mlir::PatternRewriter&) const VectorOps.cpp:0:0
Alos if you use a debugger, at the time of the crash you should be able to look at the entire backtrace and connect to the source code.
@joker-eph, I'm sorry, but I'm still having trouble finding the exact location in the code:
Attribute sourceCst;
if (!matchPattern(sourceValue, m_Constant(&sourceCst)))
return failure();
when I inspect sourceValue
using sourceValue.dump()
in LLDB, it displays %1 = llvm.mlir.constant(1 : index) : i64
. However, when I inspect sourceCst
, it only shows 1 : index
. I believe the issue may be occurring during the matchPattern call and also in foldSingleResultHook
, but I'm unsure where the folding operation is happening.
could you please assign this one to me?
@joker-eph, I'm sorry, but I'm still having trouble finding the exact location in the code:
Attribute sourceCst;
if (!matchPattern(sourceValue, m_Constant(&sourceCst)))
return failure();
when I inspect
sourceValue
usingsourceValue.dump()
in LLDB, it displays%1 = llvm.mlir.constant(1 : index) : i64
. However, when I inspectsourceCst
, it only shows1 : index
. I believe the issue may be occurring during the matchPattern call and also infoldSingleResultHook
, but I'm unsure where the folding operation is happening.
@joker-eph Could you please provide a hint for this?
@joker-eph
Is this the expected output after fix:
"builtin.module"() ({
"llvm.func"() <{CConv = #llvm.cconv<ccc>, function_type = !llvm.func<ptr (i64)>, linkage = #llvm.linkage<external>, sym_name = "malloc", unnamed_addr = 0 : i64, visibility_ = 0 : i64}> ({
}) : () -> ()
"func.func"() <{function_type = (index, memref<13x13xi64>, index) -> (), sym_name = "func2"}> ({
^bb0(%arg0: index, %arg1: memref<13x13xi64>, %arg2: index):
%0 = "arith.constant"() <{value = dense<0> : vector<1xi64>}> : () -> vector<1xi64>
"vector.print"(%0) <{punctuation = #vector.punctuation<newline>}> : (vector<1xi64>) -> ()
"func.return"() : () -> ()
}) : () -> ()
}) : () -> ()
git version: e9c6f3f5e7e23b23de4eeaa182ebfcb7d2188495
system:
Ubuntu 20.04.6 LTS (Focal Fossa)
reproduced with:
mlir-opt --canonicalize a.mlir
a.mlir:
trace: