beckhoff TE1200 — 8 Constant propagation

Constant propagation IF func(FALSE) THEN y := x; ELSE y := 2*x; END_IF In line 6, x has the range [1..10] . After line 11, y has the value range [1..20] . This results from the union of the two value ranges [1..10] and [2..20] . Conditions Sample: Conditions can restrict the value range of a variable in a code block. Several conditions can be combined. Mutually exclusive conditions can also result in an empty value range. IF y > 0 AND y x := y; ELSE x:= 0; END_IF IF x i := 99; END_IF y has the value range [1..9] in line 2. This results in the value range [0..9] for x in line 6. Combined with the condition x , this results in an empty set of possible values in line 9 for x .

The code is not accessible. The static analysis will report that the condition x always results in FALSE at this point. Loops The constant propagation will execute loops in the code until the values of the variables in the loop no longer change. It is assumed that a loop can be run through as often as required. The values determined so far are combined with the previous values. Variables that are changed within the loop have a successively growing range. The constant propagation does not assume all possible values for ranges, but only uses limits that occur in the code and also the values 0, 1, 2, 3 and 10, as these often play a role.

The easiest way to illustrate the procedure is with an example. Sample: PROGRAM MAIN VAR x : DINT; i : DINT; y : DINT; END_VAR x := 0; y := 0; FOR i := 0 TO 5 DO x := x + 1; y := i; END_FOR The constant propagation knows the following about the loop: i , x , and y are 0 at the beginning of the first execution of the loop. The condition i applies to the code in the loop. The condition i > 5 applies to the code after the loop. The constant propagation determines the following values for the variables in the loop: The following intermediate steps are carried out in detail: TE1200 128 Version: 2.11.1 i x y [0..5] [0..MAXDINT] [0..5]