Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] type-related(size_t or int) crash in simple matrix multiply example #379

Open
syheliel opened this issue Jan 7, 2024 · 0 comments

Comments

@syheliel
Copy link

syheliel commented Jan 7, 2024

reproduce

Here is the code implement matrix multiply. The keypoint is #define SIZE_TYPE size_t. Notes if the SIZE_TYPE changed into int, the code will not cause error.

compile method:

cgeist --resource-dir=$RESOURCE_DIR  ./opti.cpp -o out.execm

code

#include <iostream>

#define SIZE_TYPE size_t
const int sb = 128;

void mul(double* a, double* b, double* c, SIZE_TYPE n1, SIZE_TYPE n2, SIZE_TYPE n3) {
	for(int i=0;i<n1;i++){
		for(int j=0;j<n2;j++){
			for(int k=0;k<n3;k++){
				c[i*n3+k]+=a[i*n2+j]*b[j*n3+k];
			}
		}
	}
}

int main() {
	SIZE_TYPE n1, n2, n3;
	FILE* fi;

	n1=8192;n2=8192;n3=8192;

	double* a = (double*)malloc(n1 * n2 * 8);
	double* b = (double*)malloc(n2 * n3 * 8);
	double* c = (double*)malloc(n1 * n3 * 8);

	for (int i = 0; i < n1*n2; i++) {
        a[i] = i;
        b[i] = i;
		c[i] = 0;
	}

	return 0;
}

Error message:

cgeist: /home/xxx/Polygeist/llvm-project/mlir/lib/IR/PatternMatch.cpp:327: auto mlir::RewriterBase::eraseOp(Operation *)::(anonymous class)::operator()(Operation *) const: Assertion `mayBeGraphRegion(*op->getParentRegion()) && "expected that op has no uses"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/xxx/Polygeist/build/bin/cgeist --resource-dir=/usr/lib/llvm-16/lib/clang/16 ./opti.cpp -o out.execm
 #0 0x000055d2419ae92d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/xxx/Polygeist/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:11
 #1 0x000055d2419aee1b PrintStackTraceSignalHandler(void*) /home/xxx/Polygeist/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
 #2 0x000055d2419ace86 llvm::sys::RunSignalHandlers() /home/xxx/Polygeist/llvm-project/llvm/lib/Support/Signals.cpp:105:5
 #3 0x000055d2419af5d5 SignalHandler(int) /home/xxx/Polygeist/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x000014db38a5afd0 (/lib/x86_64-linux-gnu/libc.so.6+0x3bfd0)
 #5 0x000014db38aa9d3c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x000014db38a5af32 raise ./signal/../sysdeps/posix/raise.c:27:6
 #7 0x000014db38a45472 abort ./stdlib/abort.c:81:7
 #8 0x000014db38a45395 _nl_load_domain ./intl/loadmsgcat.c:1177:9
 #9 0x000014db38a53e32 (/lib/x86_64-linux-gnu/libc.so.6+0x34e32)
#10 0x000055d241f5a23d mlir::RewriterBase::eraseOp(mlir::Operation*)::$_1::operator()(mlir::Operation*) const /home/xxx/Polygeist/llvm-project/mlir/lib/IR/PatternMatch.cpp:326:7
#11 0x000055d241f5a11e mlir::RewriterBase::eraseOp(mlir::Operation*)::$_0::operator()(mlir::Operation*) const /home/xxx/Polygeist/llvm-project/mlir/lib/IR/PatternMatch.cpp:370:3
#12 0x000055d241f59d70 void std::__invoke_impl<void, mlir::RewriterBase::eraseOp(mlir::Operation*)::$_0&, mlir::Operation*>(std::__invoke_other, mlir::RewriterBase::eraseOp(mlir::Operation*)::$_0&, mlir::Operation*&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/invoke.h:61:7
#13 0x000055d241f59d0d std::enable_if<is_invocable_r_v<void, mlir::RewriterBase::eraseOp(mlir::Operation*)::$_0&, mlir::Operation*>, void>::type std::__invoke_r<void, mlir::RewriterBase::eraseOp(mlir::Operation*)::$_0&, mlir::Operation*>(mlir::RewriterBase::eraseOp(mlir::Operation*)::$_0&, mlir::Operation*&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/invoke.h:117:5
#14 0x000055d241f59c35 std::_Function_handler<void (mlir::Operation*), mlir::RewriterBase::eraseOp(mlir::Operation*)::$_0>::_M_invoke(std::_Any_data const&, mlir::Operation*&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_function.h:290:2
#15 0x000055d241d0805d std::function<void (mlir::Operation*)>::operator()(mlir::Operation*) const /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_function.h:591:2
#16 0x000055d241f59f93 mlir::RewriterBase::eraseOp(mlir::Operation*)::$_0::operator()(mlir::Operation*) const /home/xxx/Polygeist/llvm-project/mlir/lib/IR/PatternMatch.cpp:351:30
#17 0x000055d241f59d70 void std::__invoke_impl<void, mlir::RewriterBase::eraseOp(mlir::Operation*)::$_0&, mlir::Operation*>(std::__invoke_other, mlir::RewriterBase::eraseOp(mlir::Operation*)::$_0&, mlir::Operation*&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/invoke.h:61:7
#18 0x000055d241f59d0d std::enable_if<is_invocable_r_v<void, mlir::RewriterBase::eraseOp(mlir::Operation*)::$_0&, mlir::Operation*>, void>::type std::__invoke_r<void, mlir::RewriterBase::eraseOp(mlir::Operation*)::$_0&, mlir::Operation*>(mlir::RewriterBase::eraseOp(mlir::Operation*)::$_0&, mlir::Operation*&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/invoke.h:117:5
#19 0x000055d241f59c35 std::_Function_handler<void (mlir::Operation*), mlir::RewriterBase::eraseOp(mlir::Operation*)::$_0>::_M_invoke(std::_Any_data const&, mlir::Operation*&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_function.h:290:2
#20 0x000055d241d0805d std::function<void (mlir::Operation*)>::operator()(mlir::Operation*) const /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_function.h:591:2
#21 0x000055d241f59120 mlir::RewriterBase::eraseOp(mlir::Operation*) /home/xxx/Polygeist/llvm-project/mlir/lib/IR/PatternMatch.cpp:373:1
#22 0x000055d241f58e0a mlir::RewriterBase::replaceOp(mlir::Operation*, mlir::ValueRange) /home/xxx/Polygeist/llvm-project/mlir/lib/IR/PatternMatch.cpp:282:1
#23 0x000055d2429c4a40 MoveWhileToFor::matchAndRewrite(mlir::scf::WhileOp, mlir::PatternRewriter&) const /home/xxx/Polygeist/lib/polygeist/Passes/CanonicalizeFor.cpp:981:12
#24 0x000055d2428d103b mlir::detail::OpOrInterfaceRewritePatternBase<mlir::scf::WhileOp>::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const /home/xxx/Polygeist/llvm-project/mlir/include/mlir/IR/PatternMatch.h:330:12
#25 0x000055d2483df576 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>)::$_0::operator()() const /home/xxx/Polygeist/llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:206:31
#26 0x000055d2483df3b5 void llvm::function_ref<void ()>::callback_fn<mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>)::$_0>(long) /home/xxx/Polygeist/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:5
#27 0x000055d2406afb69 llvm::function_ref<void ()>::operator()() const /home/xxx/Polygeist/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:5
#28 0x000055d2483e0d95 void mlir::MLIRContext::executeAction<mlir::ApplyPatternAction, mlir::Pattern const&>(llvm::function_ref<void ()>, llvm::ArrayRef<mlir::IRUnit>, mlir::Pattern const&) /home/xxx/Polygeist/llvm-project/mlir/include/mlir/IR/MLIRContext.h:276:3
#29 0x000055d2483dde57 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>) /home/xxx/Polygeist/llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:227:9
#30 0x000055d242e9e4e8 (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() /home/xxx/Polygeist/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:474:17
#31 0x000055d242e9dfc1 (anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) &&::$_2::operator()() const /home/xxx/Polygeist/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:696:30
#32 0x000055d242e9df95 void llvm::function_ref<void ()>::callback_fn<(anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) &&::$_2>(long) /home/xxx/Polygeist/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:5
#33 0x000055d2406afb69 llvm::function_ref<void ()>::operator()() const /home/xxx/Polygeist/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:5
#34 0x000055d242e9d715 void mlir::MLIRContext::executeAction<(anonymous namespace)::GreedyPatternRewriteIteration, long&>(llvm::function_ref<void ()>, llvm::ArrayRef<mlir::IRUnit>, long&) /home/xxx/Polygeist/llvm-project/mlir/include/mlir/IR/MLIRContext.h:276:3
#35 0x000055d242e9ba15 (anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) && /home/xxx/Polygeist/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:704:3
#36 0x000055d242e9b737 mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) /home/xxx/Polygeist/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:730:47
#37 0x000055d241be8aa5 mlir::applyPatternsAndFoldGreedily(mlir::Operation*, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) /home/xxx/Polygeist/llvm-project/mlir/include/mlir/Transforms/GreedyPatternRewriteDriver.h:123:9
#38 0x000055d2429bb409 (anonymous namespace)::CanonicalizeFor::runOnOperation() /home/xxx/Polygeist/lib/polygeist/Passes/CanonicalizeFor.cpp:2247:9
#39 0x000055d242e120fb mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_1::operator()() const /home/xxx/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:0:17
#40 0x000055d242e12095 void llvm::function_ref<void ()>::callback_fn<mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_1>(long) /home/xxx/Polygeist/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:5
#41 0x000055d2406afb69 llvm::function_ref<void ()>::operator()() const /home/xxx/Polygeist/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:5
#42 0x000055d242e14ef5 void mlir::MLIRContext::executeAction<mlir::PassExecutionAction, mlir::Pass&>(llvm::function_ref<void ()>, llvm::ArrayRef<mlir::IRUnit>, mlir::Pass&) /home/xxx/Polygeist/llvm-project/mlir/include/mlir/IR/MLIRContext.h:276:3
#43 0x000055d242e0d843 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/xxx/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:509:17
#44 0x000055d242e0ddc4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/xxx/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:569:16
#45 0x000055d242e0ec1e mlir::detail::OpToOpPassAdaptor::runOnOperationImpl(bool) /home/xxx/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:710:20
#46 0x000055d242e0e4cd mlir::detail::OpToOpPassAdaptor::runOnOperation(bool) /home/xxx/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:693:1
#47 0x000055d242e120e6 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_1::operator()() const /home/xxx/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:501:11
#48 0x000055d242e12095 void llvm::function_ref<void ()>::callback_fn<mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_1>(long) /home/xxx/Polygeist/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:5
#49 0x000055d2406afb69 llvm::function_ref<void ()>::operator()() const /home/xxx/Polygeist/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:5
#50 0x000055d242e14ef5 void mlir::MLIRContext::executeAction<mlir::PassExecutionAction, mlir::Pass&>(llvm::function_ref<void ()>, llvm::ArrayRef<mlir::IRUnit>, mlir::Pass&) /home/xxx/Polygeist/llvm-project/mlir/include/mlir/IR/MLIRContext.h:276:3
#51 0x000055d242e0d843 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/xxx/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:509:17
#52 0x000055d242e0ddc4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/xxx/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:569:16
#53 0x000055d242e0f809 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /home/xxx/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:880:10
#54 0x000055d242e0f732 mlir::PassManager::run(mlir::Operation*) /home/xxx/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:860:60
#55 0x000055d23fc6ce53 main /home/xxx/Polygeist/tools/cgeist/driver.cc:688:25
#56 0x000014db38a461ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#57 0x000014db38a46285 call_init ./csu/../csu/libc-start.c:128:20
#58 0x000014db38a46285 __libc_start_main ./csu/../csu/libc-start.c:347:5
#59 0x000055d23fc3f931 _start (/home/xxx/Polygeist/build/bin/cgeist+0x8e2931)
Aborted (core dumped)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant