@@ -5762,7 +5762,12 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb)
57625762 base = lhs ;
57635763
57645764 if (ins -> inst_offset == 0 ) {
5765- addr = base ;
5765+ LLVMValueRef gep_base , gep_offset ;
5766+ if (mono_llvm_can_be_gep (base , & gep_base , & gep_offset )) {
5767+ addr = LLVMBuildGEP (builder , convert (ctx , gep_base , LLVMPointerType (LLVMInt8Type (), 0 )), & gep_offset , 1 , "" );
5768+ } else {
5769+ addr = base ;
5770+ }
57665771 } else if (ins -> inst_offset % size != 0 ) {
57675772 /* Unaligned load */
57685773 index = LLVMConstInt (LLVMInt32Type (), ins -> inst_offset , FALSE);
@@ -5816,7 +5821,10 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb)
58165821 t = load_store_to_llvm_type (ins -> opcode , & size , & sext , & zext );
58175822
58185823 base = values [ins -> inst_destbasereg ];
5819- if (ins -> inst_offset % size != 0 ) {
5824+ LLVMValueRef gep_base , gep_offset ;
5825+ if (ins -> inst_offset == 0 && mono_llvm_can_be_gep (base , & gep_base , & gep_offset )) {
5826+ addr = LLVMBuildGEP (builder , convert (ctx , gep_base , LLVMPointerType (LLVMInt8Type (), 0 )), & gep_offset , 1 , "" );
5827+ } else if (ins -> inst_offset % size != 0 ) {
58205828 /* Unaligned store */
58215829 index = LLVMConstInt (LLVMInt32Type (), ins -> inst_offset , FALSE);
58225830 addr = LLVMBuildGEP (builder , convert (ctx , base , LLVMPointerType (LLVMInt8Type (), 0 )), & index , 1 , "" );
@@ -5846,7 +5854,10 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb)
58465854 t = load_store_to_llvm_type (ins -> opcode , & size , & sext , & zext );
58475855
58485856 base = values [ins -> inst_destbasereg ];
5849- if (ins -> inst_offset % size != 0 ) {
5857+ LLVMValueRef gep_base , gep_offset ;
5858+ if (ins -> inst_offset == 0 && mono_llvm_can_be_gep (base , & gep_base , & gep_offset )) {
5859+ addr = LLVMBuildGEP (builder , convert (ctx , gep_base , LLVMPointerType (LLVMInt8Type (), 0 )), & gep_offset , 1 , "" );
5860+ } else if (ins -> inst_offset % size != 0 ) {
58505861 /* Unaligned store */
58515862 index = LLVMConstInt (LLVMInt32Type (), ins -> inst_offset , FALSE);
58525863 addr = LLVMBuildGEP (builder , convert (ctx , base , LLVMPointerType (LLVMInt8Type (), 0 )), & index , 1 , "" );
0 commit comments