diff --git a/src/r_compiler/llvmdrawers.cpp b/src/r_compiler/llvmdrawers.cpp index ae9dcb662..9391e7e20 100644 --- a/src/r_compiler/llvmdrawers.cpp +++ b/src/r_compiler/llvmdrawers.cpp @@ -434,6 +434,9 @@ LLVMProgram::LLVMProgram() passManagerBuilder.OptLevel = 3; passManagerBuilder.SizeLevel = 0; passManagerBuilder.Inliner = createFunctionInliningPass(); + passManagerBuilder.SLPVectorize = true; + passManagerBuilder.LoopVectorize = true; + passManagerBuilder.LoadCombine = true; passManagerBuilder.populateModulePassManager(*mModulePassManager.get()); passManagerBuilder.populateFunctionPassManager(*mFunctionPassManager.get()); } diff --git a/src/r_compiler/ssa/ssa_for_block.cpp b/src/r_compiler/ssa/ssa_for_block.cpp index f7cd6ad0b..0f7e01e19 100644 --- a/src/r_compiler/ssa/ssa_for_block.cpp +++ b/src/r_compiler/ssa/ssa_for_block.cpp @@ -13,9 +13,22 @@ SSAForBlock::SSAForBlock() SSAScope::builder().SetInsertPoint(if_basic_block); } -void SSAForBlock::loop_block(SSABool true_condition) +void SSAForBlock::loop_block(SSABool true_condition, int unroll_count) { - SSAScope::builder().CreateCondBr(true_condition.v, loop_basic_block, end_basic_block); + auto branch = SSAScope::builder().CreateCondBr(true_condition.v, loop_basic_block, end_basic_block); + if (unroll_count > 0) + { + using namespace llvm; + auto md_unroll_enable = MDNode::get(SSAScope::context(), { + MDString::get(SSAScope::context(), "llvm.loop.unroll.enable") + }); + auto md_unroll_count = MDNode::get(SSAScope::context(), { + MDString::get(SSAScope::context(), "llvm.loop.unroll.count"), + ConstantAsMetadata::get(ConstantInt::get(SSAScope::context(), APInt(32, unroll_count))) + }); + auto md_loop = MDNode::getDistinct(SSAScope::context(), { md_unroll_enable, md_unroll_count }); + branch->setMetadata(LLVMContext::MD_loop, md_loop); + } SSAScope::builder().SetInsertPoint(loop_basic_block); } diff --git a/src/r_compiler/ssa/ssa_for_block.h b/src/r_compiler/ssa/ssa_for_block.h index 4c1952c14..9dddef4d6 100644 --- a/src/r_compiler/ssa/ssa_for_block.h +++ b/src/r_compiler/ssa/ssa_for_block.h @@ -7,7 +7,7 @@ class SSAForBlock { public: SSAForBlock(); - void loop_block(SSABool true_condition); + void loop_block(SSABool true_condition, int unroll_count = 8); void end_block(); private: