@@ -719,35 +719,40 @@ def visit_then_else_blocks(self, node, liveins, then_block, else_block):
719
719
self .visit_compound_statement (node .body )
720
720
then_block = self .builder .get_insertion_block ()
721
721
then_defs = self .local_defs .copy ()
722
+ then_vals = self .lscope .copy ()
722
723
# else block
723
724
else_defs = {}
725
+ else_vals = liveins .copy ()
724
726
if node .orelse :
725
727
self .builder .set_insertion_point_to_start (else_block )
726
728
self .lscope = liveins .copy ()
727
729
self .local_defs = {}
728
730
self .visit_compound_statement (node .orelse )
729
731
else_defs = self .local_defs .copy ()
730
732
else_block = self .builder .get_insertion_block ()
733
+ else_vals = self .lscope .copy ()
731
734
732
735
# update block arguments
733
736
names = []
734
737
# variables in livein whose value is updated in `if`
735
- for name in liveins :
738
+ for name , value in liveins .items ():
739
+ # livein variable changed value in either then or else
740
+ if not _is_triton_value (value ):
741
+ continue
742
+ then_handles = flatten_values_to_ir ([then_vals [name ]])
743
+ else_handles = flatten_values_to_ir ([else_vals [name ]])
744
+ if then_handles == else_handles :
745
+ continue
746
+ names .append (name )
747
+ then_defs [name ] = then_vals [name ]
748
+ else_defs [name ] = else_vals [name ]
736
749
# check type
737
750
for defs , block_name in [(then_defs , 'then' ), (else_defs , 'else' )]:
738
- if name in defs :
739
- type_equal = type (defs [name ]) == type (liveins [name ]) # noqa: E721
740
- assert type_equal and defs [name ].type == liveins [name ].type , \
741
- f'initial value for `{ name } ` is of type { liveins [name ]} , ' \
742
- f'but the { block_name } block redefines it as { defs [name ]} '
743
- if name in then_defs or name in else_defs :
744
- names .append (name )
745
- # variable defined in then but not in else
746
- if name in then_defs and name not in else_defs :
747
- else_defs [name ] = liveins [name ]
748
- # variable defined in else but not in then
749
- if name in else_defs and name not in then_defs :
750
- then_defs [name ] = liveins [name ]
751
+ type_equal = type (defs [name ]) == type (value ) # noqa: E721
752
+ assert type_equal and defs [name ].type == value .type , \
753
+ f'initial value for `{ name } ` is of type { value } , ' \
754
+ f'but the { block_name } block redefines it as { defs [name ]} '
755
+
751
756
# variables that are both in then and else but not in liveins
752
757
# TODO: could probably be cleaned up
753
758
for name in sorted (then_defs .keys () & else_defs .keys ()):
0 commit comments