@@ -716,16 +716,25 @@ class ReplaceArrayOp: public ASR::BaseExprReplacer<ReplaceArrayOp> {
716
716
op_n_dims = x_dims.size ();
717
717
}
718
718
719
- ASR::ttype_t * x_m_type = ASRUtils::TYPE (ASR::make_Pointer_t (al, loc,
720
- ASRUtils::type_get_past_allocatable (ASRUtils::duplicate_type (al,
721
- ASRUtils::type_get_past_pointer (x->m_type ), &empty_dims))));
722
-
719
+ ASR::ttype_t * x_m_type;
720
+ if (op_expr && ASRUtils::is_simd_array (op_expr)) {
721
+ x_m_type = ASRUtils::expr_type (op_expr);
722
+ } else {
723
+ x_m_type = ASRUtils::TYPE (ASR::make_Pointer_t (al, loc,
724
+ ASRUtils::type_get_past_allocatable (ASRUtils::duplicate_type (al,
725
+ ASRUtils::type_get_past_pointer (x->m_type ), &empty_dims))));
726
+ }
723
727
ASR::expr_t * array_section_pointer = PassUtils::create_var (
724
728
result_counter, " _array_section_pointer_" , loc,
725
729
x_m_type, al, current_scope);
726
730
result_counter += 1 ;
727
- pass_result.push_back (al, ASRUtils::STMT (ASRUtils::make_Associate_t_util (
728
- al, loc, array_section_pointer, *current_expr)));
731
+ if (op_expr && ASRUtils::is_simd_array (op_expr)) {
732
+ pass_result.push_back (al, ASRUtils::STMT (ASR::make_Assignment_t (
733
+ al, loc, array_section_pointer, *current_expr, nullptr )));
734
+ } else {
735
+ pass_result.push_back (al, ASRUtils::STMT (ASRUtils::make_Associate_t_util (
736
+ al, loc, array_section_pointer, *current_expr)));
737
+ }
729
738
*current_expr = array_section_pointer;
730
739
731
740
// Might get used in other replace_* methods as well.
@@ -740,6 +749,33 @@ class ReplaceArrayOp: public ASR::BaseExprReplacer<ReplaceArrayOp> {
740
749
741
750
template <typename T>
742
751
void replace_ArrayOpCommon (T* x, std::string res_prefix) {
752
+ bool is_left_simd = ASRUtils::is_simd_array (x->m_left );
753
+ bool is_right_simd = ASRUtils::is_simd_array (x->m_right );
754
+ if ( is_left_simd && is_right_simd ) {
755
+ return ;
756
+ } else if ( ( is_left_simd && !is_right_simd) ||
757
+ (!is_left_simd && is_right_simd) ) {
758
+ ASR::expr_t ** current_expr_copy = current_expr;
759
+ ASR::expr_t * op_expr_copy = op_expr;
760
+ if (is_left_simd) {
761
+ // Replace ArraySection, case: a = a + b(:4)
762
+ if (ASR::is_a<ASR::ArraySection_t>(*x->m_right )) {
763
+ current_expr = &(x->m_right );
764
+ op_expr = x->m_left ;
765
+ this ->replace_expr (x->m_right );
766
+ }
767
+ } else {
768
+ // Replace ArraySection, case: a = b(:4) + a
769
+ if (ASR::is_a<ASR::ArraySection_t>(*x->m_left )) {
770
+ current_expr = &(x->m_left );
771
+ op_expr = x->m_right ;
772
+ this ->replace_expr (x->m_left );
773
+ }
774
+ }
775
+ current_expr = current_expr_copy;
776
+ op_expr = op_expr_copy;
777
+ return ;
778
+ }
743
779
const Location& loc = x->base .base .loc ;
744
780
bool current_status = use_custom_loop_params;
745
781
use_custom_loop_params = false ;
@@ -1587,6 +1623,9 @@ class ArrayOpVisitor : public ASR::CallReplacerOnExpressionsVisitor<ArrayOpVisit
1587
1623
1588
1624
void visit_Assignment (const ASR::Assignment_t &x) {
1589
1625
if (ASRUtils::is_simd_array (x.m_target )) {
1626
+ if (!ASR::is_a<ASR::ArrayPhysicalCast_t>(*x.m_value )) {
1627
+ this ->visit_expr (*x.m_value );
1628
+ }
1590
1629
return ;
1591
1630
}
1592
1631
if ( (ASR::is_a<ASR::Pointer_t>(*ASRUtils::expr_type (x.m_target )) &&
0 commit comments