Docsity

Effective Compiler Support for Predicated Execution Using the Hyperblock | ECE 512, Papers of Computer Architecture and Organization

Toggle sidebar
bg1
Eective Compiler Support for Predicated Execution
Using the Hyperblock
Scott A. Mahlke David C. Lin
William Y. Chen Richard E. Hank Roger A. Bringmann
Center for Reliable and High-Performance Computing
University of Illinois
Urbana-Champaign, IL 61801
Abstract
Predicated execution is an eective technique for dealing
with conditional branches in application programs. How-
ever, there are several problems associated with conventional
compiler support for predicated execution. First, all paths
of control are combined into a single path regardless of their
execution frequency and size with conventional if-conversion
techniques. Second, speculative execution is dicult to com-
bine with predicated execution. In this paper, we propose
the use of a new structure, referred to as the hyperblock,
to overcome these problems. The hyperblock is an ecient
structure to utilize predicated execution for both compile-
time optimization and scheduling. Preliminary exp erimen-
tal results show that the hyperblock is highly eective for a
wide range of superscalar and VLIW processors.
1 Introduction
Superscalar and VLIW processors can potentially provide
large performance improvements over their scalar predeces-
sors by providing multiple data paths and function units.
In order to eectively utilize the resources, sup erscalar and
VLIW compilers must expose increasing amounts of instruc-
tion level parallelism (ILP). Typically, global optimization
and scheduling techniques are utilized by the compiler to
nd sucient ILP. A common problem all global optimiza-
tion and scheduling strategies must resolve is conditional
branches in the target application. Predicated execution is
an ecient method to handle conditional branches. Predi-
cated or guarded execution refers to the conditional execu-
tion of instructions based on the value of a bo olean source
operand, referred to as the predicate. When the predicate
has value T, the instruction is executed normally and when
the predicate has value F, the instruction is treated as a
no op
. With predicated execution support provided in the
architecture, the compiler can eliminate many of the condi-
tional branches in an application.
The process of eliminating conditional branches from a
program to utilize predicated execution support is referred
to as
if-conversion
[1] [2] [3]. If-conversion was initially pro-
posed to assist automatic vectorization techniques for loops
with conditional branches. If-conversion basically replaces
conditional branches in the code with comparison instruc-
tions which set a predicate. Instructions control dependent
David Lin is now with Amdahl Corporation, Sunnyvale, CA.
on the branch are then converted to predicated instructions
dependent on the value of the corresponding predicate. In
this manner, control dependences are converted to data de-
pendences in the code. If-conversion can eliminate all non-
loop backward branches from a program.
Predicated execution support has been used eectively for
scheduling both numeric and non-numeric applications. For
numeric code, overlapping the execution of multiple loop it-
erations using software pipeline scheduling can achieve high-
performance on superscalar and VLIW pro cessors [4] [5] [6].
With the ability to remove branches with predicated exe-
cution support, more compact schedules and reduced code
expansion are achieved with software pipelining. Software
pipelining taking advantage of predicated execution sup-
port is productized in the Cydra 5 compiler [7] [8]. For
non-numeric applications, decision tree scheduling utilizes
guarded instructions to achieve large performance improve-
ments on deeply pipelined processors as well as multiple-
instruction-issue processors [9]. Guarded instructions allow
concurrent execution along multiple paths of control and ex-
ecution of instructions before the branches they depend on
may be resolved.
There are two problems, though, asso ciated with utiliz-
ing conventional compiler support for predicated execution.
First, if-conversion combines all execution paths in a region
(typically an inner loop body) into a single block. There-
fore, instructions from the entire region must be examined
each time a particular path through the region is entered.
When all execution paths are approximately the same size
and have the same frequency, this method is very eective.
However, the size and frequency of dierent execution paths
typically varies in an inner loop. Infrequently executed paths
and execution paths with comparatively larger number of
instructions often limit performance of the resultant predi-
cated block. Also, execution paths with subroutine calls or
unresolvable memory accesses can restrict optimization and
scheduling within the predicated block.
The second problem is that speculative execution does not
t in conveniently with predicated execution. Speculative
or eager execution refers to the execution of an instruction
before it is certain its execution is required. With predicated
instructions, speculative execution refers to the execution of
an instruction before its predicate is calculated. Sp eculative
execution is an important source of ILP for superscalar and
VLIW processors by allowing long latency instructions to be
initiated much earlier in the schedule.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Effective Compiler Support for Predicated Execution Using the Hyperblock | ECE 512 and more Papers Computer Architecture and Organization in PDF only on Docsity!

E ective Compiler Supp ort for Predicated Execution

Using the Hyp erblo ck

Scott A. Mahlke David C. Lin William Y. Chen Richard E. Hank Roger A. Bringmann

Center for Reliable and High-Performance Computing University of Illinois Urbana-Champaign, IL 61801

Abstract

Predicated execution is an e ective technique for dealing with conditional branches in applicatio n programs. How- ever, there are several problems asso ciated with conventional compiler supp ort for predicated execution. First, all paths of control are combined into a single path regardless of their execution frequency and size with conventional if-conversion techniques. Second, sp eculative execution is dicult to com- bine with predicated execution. In this pap er, we prop ose the use of a new structure, referred to as the hyp erblo ck, to overcome these problems. The hyp erblo ck is an ecient structure to utilize predicated execution for b oth compile- time optimization and scheduling. Preliminary exp erimen- tal results show that the hyp erblo ck is highly e ective for a wide range of sup erscalar and VLIW pro cessors.

1 Intro duction

Sup erscalar and VLIW pro cessors can p otentially provide large p erformance improvements over their scalar predeces- sors by providing multiple data paths and function units. In order to e ectively utilize the resources, sup erscalar and VLIW compilers must exp ose increasing amounts of instruc- tion level paralleli sm (ILP). Typically, global optimization and scheduling techniques are utilized by the compiler to nd sucient ILP. A common problem all global optimiza- tion and scheduling strategies must resolve is conditional branches in the target applicatio n. Predicated execution is an ecient metho d to handle conditional branches. Predi- cated or guarded execution refers to the conditional execu- tion of instructions based on the value of a b o olean source op erand, referred to as the predicate. When the predicate has value T, the instruction is executed normally and when the predicate has value F, the instruction is treated as a no op. With predicated execution supp ort provided in the architecture, the compiler can eliminate many of the condi- tional branches in an application. The pro cess of eliminatin g conditional branches from a program to utilize predicated execution supp ort is referred to as if-conversion [1] [2] [3]. If-conversion was initiall y pro- p osed to assist automatic vectorization techniques for lo ops with conditional branches. If-conversion basically replaces conditional branches in the co de with comparison instruc- tions which set a predicate. Instructions control dep endent  David Lin is now with Amdahl Corp oration, Sunnyvale, CA.

on the branch are then converted to predicated instructions dep endent on the value of the corresp onding predicate. In this manner, control dep endences are converted to data de- p endences in the co de. If-conversion can eliminate all non- lo op backward branches from a program. Predicated execution supp ort has b een used e ectively for scheduling b oth numeric and non-numeric applications. For numeric co de, overlapping the execution of multiple lo op it- erations using software pip eline scheduling can achieve high- p erformance on sup erscalar and VLIW pro cessors [4] [5] [6]. With the ability to remove branches with predicated exe- cution supp ort, more compact schedules and reduced co de expansion are achieved with software pip elini ng. Software pip elinin g taking advantage of predicated execution sup- p ort is pro ductized in the Cydra 5 compiler [7] [8]. For non-numeric applications , decision tree scheduling utilizes guarded instructions to achieve large p erformance improve- ments on deeply pip elined pro cessors as well as multiple- instruction-issue pro cessors [9]. Guarded instructions allow concurrent execution along multiple paths of control and ex- ecution of instructions b efore the branches they dep end on may b e resolved. There are two problems, though, asso ciated with utiliz- ing conventional compiler supp ort for predicated execution. First, if-conversion combines all execution paths in a region (typically an inner lo op b o dy) into a single blo ck. There- fore, instructions from the entire region must b e examined each time a particular path through the region is entered. When all execution paths are approximately the same size and have the same frequency, this metho d is very e ective. However, the size and frequency of di erent execution paths typically varies in an inner lo op. Infrequently executed paths and execution paths with comparatively larger numb er of instructions often limit p erformance of the resultant predi- cated blo ck. Also, execution paths with subroutine calls or unresolvable memory accesses can restrict optimization and scheduling within the predicated blo ck. The second problem is that sp eculative execution do es not t in conveniently with predicated execution. Sp eculative or eager execution refers to the execution of an instruction b efore it is certain its execution is required. With predicated instructions, sp eculative execution refers to the execution of an instruction b efore its predicate is calculated. Sp eculative execution is an imp ortant source of ILP for sup erscalar and VLIW pro cessors by allowing long latency instructions to b e initiated much earlier in the schedule.

In this pap er, we prop ose the use of a structure, referred to as the hyperblock , to overcome these two problems. A hyp erblo ck is a set of predicated basic blo cks in which con- trol may only enter from the top, but may exit from one or more lo cations. Hyp erblo cks are formed using a mo di- ed version of if-conversion. Basic blo cks are included in a hyp erblo ck based on their execution frequency, size, and in- struction characteristics. Sp eculative execution is provided by p erforming predicate promotion within a hyp erblo ck. Su- p erscalar optimization, scheduling , and register allo cation may also b e e ectively applied to the resultant hyp erblo cks. The remainder of this pap er consists of four sections. In Section 2, the architecture supp ort we utilize for predicated execution is discussed. Section 3 presents the hyp erblo ck and its asso ciated transformations. In Section 4, a prelim- inary evaluation on the e ectiveness of the hyp erblo ck is given. Finally, some concluding remarks are o ered in Sec- tion 5.

2 Supp ort for Predicated Execution

An architecture supp orting predicated execution must b e able to conditional l y nullify the side e ects of selected in- structions. The condition for nulli cati on , the predicate, is stored in a predicate register le and is sp eci ed via an ad- ditional source op erand added to each instruction. The con- tent of the sp eci ed predicate register is used to squash the instruction within the pro cessor pip eline. The architecture chosen for mo di cation to allow predicated execution, the IMPACT architecture mo del, is a statically scheduled, mul- tiple instruction issue machine supp orted by the IMPACT-I compiler [10 ]. The IMPACT architecture mo del mo di ca- tions for predicated execution are based up on that of the Cydra 5 system [7]. Our prop osed architectural mo di ca- tions serve to reduce the dep endence chain for setting pred- icates and to increase the numb er of instructions allowed to mo dify the predicate register le. This section will present the implementation of predicated execution in the Cydra 5, and discuss the implications that the prop osed mo di cations to the IMPACT architecture mo del will have on the archi- tecture itself, instruction set, and instruction scheduling.

2.1 Supp ort in the Cydra 5 System

The Cydra 5 system is a VLIW, multipro cessor system uti- lizing a directed-data ow architecture. Each Cydra 5 in- struction word contains 7 op erations, each of which may b e individua ll y predicated. An additional source op erand added to each op eration sp eci es a predicate lo cated within the predicate register le. The predicate register le is an array of 128 b o olean (1-bit) registers. Within the pro cessor pip eline after the op erand fetch stage, the predicate sp ec- i ed by each op eration is examined. If the content of the predicate register is 1', the instruction is allowed to pro ceed to the execution stage, otherwise it is squashed. Essentially, op erations whose predicates are0' are converted to no ops prior to entering the execution stage of the pip eline. The predicate sp eci ed by an op eration must thus b e known by the time the op eration leaves the op erand fetch stage.

for (i=0; i<100; i++) if (A[i]  50) (a) j = j+2; else j = j+1;

mov r1,0 mov r1, mov r2,0 mov r2, ld r3,addr(A) ld r3,addr(A) L1: L1: ld r4,mem(r3+r2) ld r4,mem(r3+r2) bgt r4,50,L2 gt r6,r4, add r5,r5,2 stu p1,r jump L3 stu bar p2,r L2: add r5,r5,2 if p add r5,r5,1 add r5,r5,1 if p L3: add r1,r1, add r1,r1,1 add r2,r2, add r2,r2,4 blt r1,100,L blt r1,100,L

(b) (c)

Figure 1: Example of if-then-else predication, (a) source co de segment, (b) assembly co de segment, (c) assembly co de segment after predication.

The content of a predicate register may only b e mo di ed by one of 3 op erations: stu , stu bar, or brtop. The stu op eration takes as op erands a destination predicate register and a b o olean value, as well as, a source predicate register as describ ed ab ove. The b o olean value is typically pro duced us- ing a comparison op eration. If the predicate value is 1', the destination predicate register is assigned the b o olean value, otherwise the op eration is squashed. The stu bar op eration functions in the same manner, except the destination predi- cate register is set to the inverse of the b o olean value when the predicate value is1'. The brtop op eration is used for lo op control and sets the predicate controlling the next iter- ation by comparing the contents of a lo op iteration counter to the lo op b ound. Figures 1a and 1b show a simple for-lo op containing an if- then-else conditional and its corresp onding assembly co de. To set the mutually exclusive predicates for the di erent exe- cution paths shown in this example, requires 3 instructions, as shown in Figure 1c. First, a comparison must b e p er- formed, followed by a stu to set the predicate register for the true path (predicated on p1 in Figure 1c) and a stu bar to set the predicate register for the false path (predicated on p2 in Figure 1c). This results in a minimum dep endence dis- tance of 2 from the comparison to the rst p ossible reference of the predicate b eing set.

2.2 Supp ort in the IMPACT Architecture

The prop osed mo di cations to the Cydra 5 metho d for the IMPACT architecture mo del seek to reduce the numb er of instructions^1 required to set a predicate and reduce the de- p endence length from the setting of a predicate to its rst use. Figure 2 shows a basic mo del of a sup erscalar pro cessor (^1) In this context, instruction refers to a sup erscalar instruction, as opp osed to a VLIW instruction as in Cydra 5.

cussed.

3.1 Hyp erblo ck Blo ck Selection

The rst step of hyp erblo ck formation is deciding which ba- sic blo cks in a region to include in the hyp erblo ck. The region of blo cks to cho ose from typically is the the b o dy of an inner most lo op. However, other regions, including non-lo op co de with conditionals and outer lo ops containing nested lo ops, may b e chosen. Conventional techniques for if-conversion predicate all blo cks within a single-lo op nest region together [13]. For hyp erblo cks, though, only a subset of the blo cks are chosen to improve the e ectiveness of com- piler transformations. Also, in programs with many p ossible paths of execution, combining all paths into a single predi- cated blo ck may pro duce an overall loss of p erformance due to limited machine resources (fetch units or function units). To form hyp erblo cks, three features of each basic blo ck in a region are examined, execution frequency, size, and instruc- tion characteristics. Execution frequency is used to exclude paths of control which are not often executed. Removing infrequent paths reduces optimization and scheduling con- straints for the frequent paths. The second feature is basic blo ck size. Larger basic blo cks should b e given less prior- ity for inclusion than smaller blo cks. Larger blo cks utilize many machine resources and thus may reduce the p erfor- mance of the control paths through smaller blo cks. Finally, the characteristics of the instructions in the basic blo ck are considered for inclusion in the hyp erblo ck. Basic blo cks with hazardous instructions, such as pro cedure calls and unresolv- able memory accesses, are given less priority for inclusio n. Typically hazardous instructions reduce the e ectiveness of optimization and scheduling for all instructions in the hy- p erblo ck. A heuristic function which considers all three issues is shown b elow.

B S Vi = (K ^ w^ sizeig e^ ht bb^ bbii  w^ siz eig^ e ht^ main main^ path path^11  bb chari )

The Blo ck Selection Value (BSV) is calculated for each basic blo ck considered for inclusion in the hyp erblo ck. The weight and size of each basic blo ck is normalized against that of the \main path". The main path is the most likely executed control path through the region of blo cks considered for in- clusion in the hyp erblo ck. The hyp erblo ck initially contains only blo cks along the main path. The variable bb chari is the characteristic value of each basic blo ck. The maximum value of bb chari is 1. Blo cks containing hazardous instruc- tions have bb chari less than 1. The variable K is a machine dep endent constant to represent the issue rate of the pro- cessor. Pro cessors with more resources can execute more instructions concurrently, and therefore are likely to take advantage of larger hyp erblo cks. An example to illustrate hyp erblo ck blo ck selection is shown in Figure 4a. This example shows a weighted con- trol ow graph for a program lo op segment. The numb ers asso ciated with each no de and arc represent the dynamic fre- quency each basic blo ck is entered and each control transfer is traversed, resp ectively. For simplici ty, this example con- siders only blo ck execution frequency as the criterion for hyp erblo ck blo ck selection. The main path in this example

Y Y

Z Z

E

A A 100

B 60

C 40

60 40

55 D 55

100 99 1

1

5

5

F 5

F 5

E’ 5

E 95

D 55

B 60

100

1

C 40

60 40

40

55 55

40

5 55

5

94.05 0.

4.95 0.

(a) (b)

Z

E’

F

Y

ABCDE

(c)

Figure 4: An example of hyp erblo ck formation, (a) af- ter blo ck selection, (b) after tail duplication , (c) after if- conversion.

is blo cks A, B, D, and E. Blo ck C is also executed frequently, so it is selected as part of the hyp erblo ck. However, Blo ck F is not executed frequently, and is excluded from the hyp er- blo ck.

3.2 Hyp erblo ck Formation

After the blo cks are selected, two conditions must b e satis- ed b efore the selected blo cks may b e if-converted and trans- formed into a hyp erblo ck. Condition 1 : There exist no incoming control ow arcs from outside basic blo cks to the selected blo cks other than to the entry blo ck. Condition 2 : There exist no nested inner lo ops inside the selected blo cks. These conditions ensure that the hyp erblo ck is entered only from the top, and the instructions in a hyp erblo ck are ex- ecuted at most once b efore the hyp erblo ck is exited. Tail duplication and lo op p eeling are used to transform the ba- sic blo cks selected for a hyp erblo ck to meet the conditions. After the group of basic blo cks satis es the conditions, they may b e transformed using the if-conversion algorithm de- scrib ed later in this section. Tail Duplication. Tail duplication is used to remove con- trol ow entry p oints into the selected blo cks (other than the entry blo ck) from blo cks not selected for inclusio n in the hyp erblo ck. In order to remove this control ow, blo cks which may b e entered from outside the hyp erblo ck are repli- cated. A tail duplication algorithm transforms the control ow graph by rst marking all the ow arcs that violate Con- dition 1. Then all selected blo cks with a direct or indirect predecessor not in the selected set of blo cks are marked. Fi- nally, all the marked blo cks are duplicated and the marked ow arcs are adjusted to transfer control to the corresp ond- ing duplicate blo cks. To reduce co de expansion, blo cks are duplicated at most one time by keeping track of the current set of duplicated blo cks.

A

B

C

D

Y

Z

A

D

Y

Z

D’

B

C

B’

C’

(a) (b)

Figure 5: An example of lo op p eeling, (a) original ow graph, (b) after p eeling one iteration of the inner lo op and tail du- plication.

An example to illustrate tail duplication is shown in Fig- ure 4b. In this example blo ck E contains a control ow entry p oint from a blo ck not selected for the hyp erblo ck (blo ck F). Therefore, blo ck E is duplicated and the control ow arc from F to E is adjusted to the duplicated blo ck E. The selected blo cks after tail duplicati on are only entered from outside blo cks through the entry blo ck, therefore Condition 1 is satis ed.

Lo op Peeling. For lo op nests with inner lo ops that iter- ate only a small numb er of times, ecient hyp erblo cks can b e formed by including b oth outer and inner lo ops within a hyp erblo ck. However, to satisfy Condition 2, inner lo ops contained within the selected blo cks must b e broken. Lo op p eeling is an ecient transformation to accomplish this task. Lo op p eeling unravels the rst several iterations of a lo op, creating a new set of co de for each iteration. The p eeled iter- ations are then included in the hyp erblo ck, and the original lo op b o dy is excluded. A lo op is p eeled the average numb er of times it is exp ected to iterate based on execution pro le information. The original lo op b o dy then serves to execute when the actual numb er of iterations exceeds the exp ected numb er. An example illustratin g lo op p eeling is shown in Figure 5. All the blo cks have b een selected for one hyp erblo ck, how- ever there is an inner lo op consisting of blo cks B and C. The inner lo op is thus p eeled to eliminate the backedge in the hyp erblo ck. In this example, it assumed the lo op executes an average of one iteration. Note also that tail duplication must b e applied to duplicate blo ck D after p eeling is applied. After p eeling and tail duplicati on (Figure 5b), the resultant hyp erblo ck, blo cks A, B^0 , C^0 , and D, satis es Conditions 1 and 2.

No de Splitting. After tail duplication and lo op p eeling, no de splitting may b e applied to the set of selected blo cks to eliminate dep endences created by control path merges. At merge p oints, the execution time of all paths is typically dictated by that of the longest path. The goal of no de split- ting is to completely eliminate merge p oints with sucient co de duplicati on. No de splitting essentially duplicates all blo cks subsequent to the merge p oint for each path of con-

trol entering the merge p oint. In this manner, the merge p oint is completely eliminated by creating a separate copy of the shared blo cks for each path of control. No de split- ting is esp ecially e ective for high-issue rate pro cessors in control-intensive programs where control and data dep en- dences limit the numb er of indep endent instructions. A problem with no de splitting is that it results in large amounts of co de expansion. Excessive no de splitting may limit p erformance within a hyp erblo ck by causing many un- necessary instructions to b e fetched and executed. There- fore, only selective no de splitting should b e p erformed by the compiler. A heuristic function for no de splitting imp or- tance is shown b elow.

F S Vi = (K ^ w siz^ eig e^ ht f^ flow^ lowii  w^ siz eig^ e ht^ main main^ path path^11  bb chari )

The Flow Selection Value (FSV) is calculated for each con- trol ow edge in the blo cks selected for the hyp erblo ck that contain two or more incoming edges, e.g., a merge p oint. W eig ht f l owi is the execution frequency of the control ow edge. S iz e f l owi is the numb er of instructions that are ex- ecuted from the entry blo ck to the p oint of the ow edge. The other parameters are the same parameters used in cal- culating the BSV. After the FSVs are computed, the no de splitting algorithm pro ceeds by starting from the no de with the largest di erences b etween the FSVs asso ciated with its incoming ow edges. Large di erences among FSVs indicate highly unbalanced control ow paths. Thus, basic blo cks with the largest di erence should b e split rst. No de split- ting continues until there are no more blo cks with 2 or more incoming edges or no di erence in FSVs ab ove a certain threshold. Our no de splitting algorithm also places an up- p er limit on the amount of no de splitting applied to each hyp erblo ck. If-conversion. If-conversion replaces a set of basic blo cks containing conditional control ow b etween the blo cks with a single blo ck of predicated instructions. Figure 4c illustrates a resultant ow graph after if-conversion is applied. In our current implementation, a variant of the RK if-conversion algorithm is utilized for hyp erblo ck formation [3]. The RK algorithm rst calculates control dep endence information b e- tween all basic blo cks selected for the hyp erblo ck [12]. One predicate register is then assigned to all basic blo cks with the same set of control dep endences. Predicate register de ning instructions are inserted into all basic blo cks which are the source of the control dep endences asso ciated with a partic- ular predicate. Next, data ow analysis is used to deter- mine predicates that may b e used b efore b eing de ned, and inserts resets (pred clear instructions) to these predicates in the entry blo ck of the hyp erblo ck. Finally, conditional branches b etween basic blo cks selected for the hyp erblo ck are removed, and instructions are predicated based on their assigned predicate. An example co de segment illustratin g hyp erblo ck forma- tion is shown in Figure 6. In the example, all blo cks shown are selected for the hyp erblo ck except blo ck 5. A control entry p oint from blo ck 5 to 7 is eliminated with tail duplica- tion. If-conversion is then applied to the resultant set of se- lected blo cks. A single predicate (p1) is required for this set of blo cks. Instructions in blo ck 2 are predicated on p1 true and instructions in blo ck 3 are predicated on p1 false. In-

instruction promotion 1() f for each instruction, op(x), in the hyp erblo ck f if all the following conditions are true:

  1. op(x) is predicated.
  2. op(x) has a destination register.
  3. there is a unique op(y ); y < x; such that dest(y ) = pr ed(x).
  4. dest(x) is not live at op(y ).
  5. dest(j ) 6 = dest(x) in fop(j ); j = y + 1 : : : x 1 g. then do: set pr ed(x) = pr ed(y ). g g

Figure 9: Algorithm for typ e 1 instruction promotion.

the predicated instruction and the instruction which sets the corresp onding predicate value. Therefore, instructions can b e scheduled b efore their corresp onding predicate are determined. Instruction promotion is e ective by allowing long latency instructions, such as memory accesses, to b e initiated early. Tirumalai et al. rst investigated instruc- tion promotion to enable sp eculative execution for software pip elined rep eat-until lo ops [13]. In this pap er, instruction promotion is extended to more general co de sequences in the context of the hyp erblo ck. Promoted instructions execute regardless of their original predicate's value. Therefore, promoted instructions must not overwrite any register or memory lo cation which is re- quired for correct program execution. Also, exceptions for sp eculative instructions should only b e rep orted if the sp ec- ulative instruction was supp osed to execute in the original co de sequence. Exceptions for sp eculative instructions are assumed to b e handled with sentinel scheduling architecture and compiler supp ort [14]. Therefore, hyp erblo ck instruc- tion promotion concentrates on handling the rst condition. Three algorithms for instruction promotion are utilized to handle di erent typ es of instructions. The rst algorithm, shown in Figure 9, is used for the simplest form of promo- tion (typ e 1). Typ e 1 instruction promotion is utilized for instructions with predicates that are not de ned multiple times. When the destination of the instruction considered for promotion is not live (de ned b efore used along all p ossi- ble control paths) at the de nition p oint of its predicate, its predicate can b e promoted to that of the predicate de ni- tion instruction it is dep endent up on. In this manner, each application of typ e 1 promotion reduces the predicate depth by one until the null predicate is reached. An example illustratin g typ e 1 promotion is shown in Fig- ure 10a (the original co de sequence is shown in Figure 6c). The load instruction indicated by the arrow is promoted with a typ e 1 promotion. Since the instruction which de nes pred- icate p1 is not predicated, the indicated instruction is also promoted to b e always executed. After promotion, the load instruction is no longer ow dep endent on the predicate com- parison instruction and can b e scheduled in the rst cycle of the hyp erblo ck. Typ e 2 instruction promotion is utilized for instructions with predicates de ned multiple times. The algorithm (Fig- ure 11) is similar to typ e 1 promotion except that the in- struction is promoted all the way to the null predicate. A single level of promotion cannot b e utilized due to the mul-

L1: loadpred_le r1, p1,MEM(A) r1, 0 add r2, r1, 1 (p1 F) addadd r4,r4, r4,r4, r2 1 (p1(p1 T)F) addbgt r2,r4, r1,0, L5 1 (p1 T) substore r4, MEM(r4), r4, (^1) r bne r4, 0, L (a)

load r4, MEM(r6) (p1 F)

L1: loadpred_le r1, p1,MEM(A) r1, 0 add r2, r1, 1 (p1 F)

addadd r4,r2, r4,r1, 11 (p1(p1 T)T) bgtsub r4,r4, 0,r4, L5 1 storebne r4, MEM(r4), 0, L1 r

add r4, r5, r2 (p1 F)

(b)

loadload r3,r5, MEM(B)MEM(r6)

L1: load r1, MEM(A)pred_le p1, r1, 0

bgtsub r4, 0, L5r4, r4, 1 store MEM(r4), r2bne r4, 0, L

add r2, r1, 1 addadd r4, r5, r2 (p1 F)r4, r4, 1 (p1 T)

(c)

load r3, MEM(B) load r3, MEM(B)load r5, MEM(r6)

Figure 10: Example of hyp erblo ck-sp eci c optimizations, (a) after typ e 1 instruction promotion, (b) after renaming in- struction promotion, (c) after instruction merging.

instruction promotion 2() f for each instruction, op(x), in the hyp erblo ck f if all the following conditions are true:

  1. op(x) is predicated.
  2. op(x) has a destination register.
  3. there exists more than one op(y ); y < x; such that dest(y ) = pr ed(x).
  4. dest(x) is not live at any instructions which either de ne pr ed(x) or de ne an ancestor of pr ed(x) in the PHG.
  5. dest(j ) 6 = dest(i) in fop(j ); j = i + 1 : : : x 1 g where op(i) is all ops which de ne pr ed(x) or ancestors to pr ed(x). then do: set pr ed(x) = ;. g g

Figure 11: Algorithm for typ e 2 instruction promotion.

tiple de nitions of the instruction's predicate each p ossibly predicated on di ering values. Many instructions cannot b e promoted due to their desti- nation variable b eing live on alternate control paths (violate condition 4 in b oth typ e 1 and typ e 2 promotion). Promo- tion can b e p erformed, though, if the destination register of the instruction is renamed. An algorithm to p erform re- naming instruction promotion is shown in Figure 12. After an opp ortunity for renaming promotion is found, uses of the destination of the promoted instruction are up dated with the renamed value. A move instruction must b e inserted into the hyp erblo ck to restore the value of the original register when the original control path is taken. An example of renaming instruction promotion is shown in Figure 10b. The load instruction indicated by the arrow cannot b e promoted with either typ e 1 or typ e 2 promotion b ecause r4 is live at the de nition p oint of the predicate p (the use of r4 on the p1 true control path causes the variable to b e live at the de nition of p1). However, renaming the destination of the load allows it to b e promoted. The use of r4 in the subsequent add is also adjusted to the new desti- nation (r5) to account for the renaming. Note also that the move instruction is not necessary here b ecause r4 is immedi- ately rede ned. In normal application of this optimization, the move is inserted, and subsequently deleted by dead co de elimination. Instruction Merging. Instruction merging combines two instructions in a hyp erblo ck with complementary pred- icates into a single instruction which will execute whether the predicate is true or false. This technique is derived from partial redundancy elimination [15]. The goal of instruction

renaming and promotion() f for each instruction, op(x), in the hyp erblo ck f if all the following conditions are true:

  1. op(x) cannot b e promoted by either typ e 1 or typ e 2.
  2. there exists op(y ); y > x such that sr c(y ) = dest(x) and op(x) dominates op(y ).
  3. dest(x) 6 = dest(j ) in fop(j ); j = x + 1 : : : y 1 g for all op(y ) in (2). then do: rename dest(x) to new register. rename all sr c(y ) in (2) to new dest(x). add new move instruction, op(z ), immediately following op(x) to move the new dest(x) to the old dest(x). pr ed(z ) = pr ed(x). pr ed(x) = ;. g g

Figure 12: Algorithm for renaming instruction promotion.

instruction merging() f for each instruction, op(x), in the hyp erblo ck f if all the following conditions are true:

  1. op(x) can b e promoted with typ e 1 promotion.
  2. op(y ) can b e promoted with typ e 1 promotion.
  3. op(x) is an identical instruction to op(y ).
  4. pr ed(x) is the complement form of pr ed(y ).
  5. the same de nitions of sr c(x) reach op(x) and op(y )
  6. op(x) is placed b efore op(y ). then do: promote op(x). delete op(y ). g g

Figure 13: Algorithm for instruction merging.

merging is to remove redundant computations along multi- ple paths of control in the hyp erblo ck. An algorithm to p er- form instruction merging is shown in Figure 13. Identical in- structions with complementary predicates are rst identi ed within a hyp erblo ck. When the source op erands de nitions reaching each instruction are the same, an opp ortunity for instruction merging is found. Instruction merging is accom- plished by p erforming a typ e 1 promotion of the lexically rst instruction and eliminatin g the second instruction.^2 In- struction merging not only reduces the size of hyp erblo cks, but also allows for sp eculative execution of the resultant in- struction. An example of hyp erblo ck instruction merging is shown Figure 10c. In this co de segment, there are two add instruc- tions (add r2, r1, 1) predicated on complementary predicates in the hyp erblo ck. After instruction merging, the rst add is promoted with typ e 1 promotion to the `0' predicate and the second add is eliminated.

3.5 Extending Conventional Compiler Tech- niques to use Hyp erblo cks

After control ow information for hyp erblo cks is derived (Section 3.3), conventional optimization , register allo cation,

(^2) Note that instruction merging may app ear to undo some of the e ects of no de splitting. However, instructions may only b e merged when they are dep endent on the same instructions for source op erands (cond 5), thus no de splitting is only undone for instructions it was not e ective for.

and instruction scheduling techniques can b e extended in a straight forward manner to work with hyp erblo cks. Di ering from basic blo cks, control ow within hyp erblo cks is not se- quential. However, a complete control ow graph among all instructions within a hyp erblo ck may b e constructed. There- fore, compiler transformations which utilize the sequential- ity inherent to basic blo cks must just b e mo di ed to handle arbitrary control ow among instructions. Hyp erblo cks provide additional opp ortunities for improve- ment with conventional compiler techniques. Traditional global techniques must b e conservative and consider all con- trol paths b etween basic blo cks. Sup erblo ck techniques only consider a single path of control at a time through a lo op or straight line co de and thus may miss some p otential opti- mizations that could b e found across multiple paths. How- ever, a hyp erblo ck may contain anywhere from one to all paths of control, and therefore can resolve many of the limi- tations of sup erblo ck techniques and traditional global tech- niques.

4 Performance Evaluation

In this section, the e ectiveness of the hyp erblo ck is analyzed for a set of non-numeric b enchmarks.

4.1 Metho dology

The hyp erblo ck techniques describ ed in this pap er have b een implemented in the IMPACT-I compiler. The IMPACT- I compiler is a prototyp e optimizing compiler designed to generate ecient co de for VLIW and sup erscalar pro cessors. The compiler utilizes a machine description le to generate co de for a parameterized sup erscalar pro cessor. The machine description le characterizes the instruction set, the microarchitecture (including the numb er and typ e of instructions that can b e fetched/issued in a cycle and the in- struction latencies), and the co de scheduling mo del. For this study, the underlying microarchitecture is assumed to have register interlo cking and an instruction set and latencies that are similar to the MIPS R2000. The pro cessor is assumed to supp ort sp eculative execution of all instructions except store and branch instructions. Furthermore when utilizin g hyp erblo ck techniques, the pro cessor is assumed to supp ort predicated execution (as describ ed in Section 2) with an un- limited supply of predicate registers. For each machine con guration, the execution time, as- suming a 100% cache hit rate, is derived from execution- driven simulation. The b enchmarks used in this exp eriment consist of 12 non-numeric programs, 3 from the SPEC set, eqntott, espresso, li , and 9 other commonly used applica- tions, cccp, cmp, compress, grep, lex, qsort, tbl, wc, yacc.

4.2 Results

The p erformance of the hyp erblo ck techniques are compared for sup erscalar pro cessors with issue rates 2, 4, and 8. The issue rate is the maximum numb er of instructions the pro- cessor can fetch and issue p er cycle. No limitation has b een placed on the combination of instructions that can b e is- sued in the same cycle. Performance is rep orted in terms

Registers

hyperblocks

1

10

100

1000

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 32+

PR PR

Figure 17: Predicate register usage distribution comparison, (PR1) without complementary predicate registers, (PR2) with complementary predicate registers.

nary evaluation of the hyp erblo ck structure. The evaluation do es not include compiler optimizations to increase ILP for sup erscalar pro cessors, such as lo op unrollin g or induction variable expansion, applied to any structures. Currently, these optimizations are available for sup erblo cks within the IMPACT-I compiler, however they have not b een fully im- plemented for the hyp erblo ck. To make a fair comparison, sup erblo ck ILP optimizations were disabled for this study. A complete analysis of the hyp erblo ck, though, requires ILP optimizations b e applied. In our current research, we are incorp orating ILP optimizations with hyp erblo cks and eval- uating their e ectiveness.

5 Concluding Remarks

Conventional compiler supp ort for predicated execution has two ma jor problems: all paths of control are combined into a single path with conventional if-conversion, and sp eculative execution is not allowed in predicated blo cks. In this pap er, the hyp erblo ck structure is intro duced to overcome these problems. Hyp erblo cks are formed by selectively including basic blo cks in the hyp erblo ck according to their execution frequency, size, and instruction characteristics. Systemati- cally excluding basic blo cks from the hyp erblo cks provides additional optimization and scheduling opp ortunities for in- structions within the hyp erblo ck. Sp eculative execution is enabled by p erforming instruction promotion and instruc- tion merging on the resultant hyp erblo cks. Preliminary ex- p erimental results show that hyp erblo cks can provide sub- stantial p erformance gains over other structures. Hyp er- blo cks are most e ective for higher issue rate pro cessors where there are sucient resources to schedule instructions for multiple paths of control. However, additional sup er- scalar optimization and scheduling techniques must b e in- corp orated with hyp erblo cks to measure their full e ective- ness.

Acknowledgements

The authors would like to thank Bob Rau at HP Labs along with all memb ers of the IMPACT research group for their comments and suggestions. This research has b een sup- p orted by JSEP under Contract N00014-90-J-1270, Dr. Lee Ho evel at NCR, the AMD 29K Advanced Pro cessor Devel- opment Division, Matsushita Electric Industrial Co. Ltd.,

Hewlett-Packard, and NASA under Contract NASA NAG 1-613 in co op eration with ICLASS.

References

[1] R. A. Towle, Control and Data Dependence for Program Transformations. PhD thesis, Department of Computer Sci- ence, University of Illinois, Urbana-Champaign, IL, 1976. [2] J. R. Allen, K. Kennedy, C. Porter eld, and J. Warren, \Con- version of control dep endence to data dep endence," in Pro- ceedings of the 10th ACM Symposium on Principles of Pro- gramming Languages, pp. 177{189, January 1983. [3] J. C. H. Park and M. S. Schlansker, \On predicated execu- tion," Tech. Rep. HPL-91-58, HP Lab oratories, Palo Alto, CA, May 1991. [4] B. R. Rau and C. D. Glaeser, \Some scheduling techniques and an easily schedulable horizontal architecture for high p erformance scienti c computing," in Proceeding s of the 20th Annual Workshop on Microprogramming and Microarchitec- ture, pp. 183{198, Octob er 1981. [5] M. S. Lam, \Software pip elining: An e ective scheduling technique for VLIW machines," in Proceedings of the ACM SIGPLAN 1988 Conference on Programming Language De- sign and Implementation, pp. 318{328, June 1988. [6] A. Aiken and A. Nicolau, \Optimal lo op parallelization," in Proceedings of the ACM SIGPLAN 1988 Conference on Pro- gramming Language Design and Implementation, pp. 308{ 317, June 1988. [7] B. R. Rau, D. W. L. Yen, W. Yen, and R. A. Towle, \The Cydra 5 departmental sup ercomputer," IEEE Computer, pp. 12{35, January 1989. [8] J. C. Dehnert, P. Y. T. Hsu, and J. P. Bratt, \Overlapp ed lo op supp ort in the Cydra 5," in Proceedings of the 17th International Symposium on Computer Architecture, pp. 26{ 38, May 1989. [9] P. Y. T. Hsu and E. S. Davidson, \Highly concurrent scalar pro cessing," in Proceedings of the 13th International Sym- posium on Computer Architecture, pp. 386{395, June 1986. [10] P. P. Chang, S. A. Mahlke, W. Y. Chen, N. J. Warter, and W. W. Hwu, \IMPACT: An architectural framework for multiple-instruction-issue pro cessors," in Proceedings of the 18th International Symposium on Computer Architec- ture, pp. 266{275, May 1991. [11] W. W. Hwu, S. A. Mahlke, W. Y. Chen, P. P. Chang, N. J. Water, R. A. Bringmann, R. G. Ouellette, R. E. Hank, T. Kiyohara, G. E. Haab, J. G. Holm, and D. M. Lavery, \The sup erblo ck: An e ective structure for VLIW and su- p erscalar compilation," To appear Journal of Supercomput- ing, January 1993. [12] J. Ferrante, K. J. Ottenstein, and J. D. Warren, \The program dep endence graph and its use in optimization," ACM Transactions on Programming Languages and Sys- tems, vol. 9, pp. 319{349, July 1987. [13] P. Tirumalai, M. Lee, and M. Schlansker, \Parallelization of lo ops with exits on pip elined architectures," in Proceedings of Supercomputing '90, Novemb er 1990. [14] S. A. Mahlke, W. Y. Chen, W. W. Hwu, B. R. Rau, and M. S. Schlansker, \Sentinel scheduling for VLIW and sup erscalar pro cessors," in Proceeding s of 5th International Conference on Architectural Support for Programming Languages and Operating Systems, Octob er 1992. [15] E. Morel and C. Renviose, \Global optimization by suppres- sion of partial redundancies," Communications of the ACM, pp. 96{103, February 1979.