Question

Suppose we have the following, (jf, A, LABEL1) (add, t4, i, j) (add, t5, t4, 3)...

Suppose we have the following,

(jf, A, LABEL1)
(add, t4, i, j)
(add, t5, t4, 3)
(assign, a, t5)
(LABEL1:)
(add, t6, i, j)
(add, t7, t6, 5)
(assign, b, t7)

Can Common Sub-expression Elimination be applied? If so, show the new code.

Homework Answers

Answer #1

Yes. We can apply common sub-expression Elimination here. Sub expression elimination is used when we have identical computations or operations repeated that can be replaced with another variable so that we only need to compute that once. If the assignment and retrieval of this value is having less cost than performing the o[eration multiple times we can then use the sub-expression elimination.

In the given example we can see that adding I and j is repeated. so we can use the Sub expression elimination by introducing an extra variable to store the result of the addition of i and j so that we can use this variable whenever we need (i+j)

so we can add a variable temp and assign the value of i+j to it as shown

(add,temp,i,j)

now we can use it to eliminate line 2 and line 6. Because in these lines we just find i+j and assign it to t4 and t6 respectively. Now we have i+j in temp so we don't need to assign it to any other variable we can straight up use the variable temp instead of this. so the line 3 and 7 in question becomes :

line 3: (add,t5,temp,3)

line 7: (add,t7,temp,5)

The complete code after common sub-expression elimination is given below

(if,A,LABEL1)
(add,temp,i,j)
(add,t5,temp,3)
(assign,a,t5)
(LABEL1:)
(add,t7,temp,5)
(assign,b,t7)
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Consider executing the following code on the pipelined datapath that we discussed in class. a). During...
Consider executing the following code on the pipelined datapath that we discussed in class. a). During the 5th cycle, which registers are being read and which register(s) will be written (using the register file)? b). Explain what the forwarding unit is doing during the 5th cycle of execution. Which registers are being compared? List all pairs of registers that are compared during the 5th cycle for the forwarding unit. (First, you need to determine which instruction's values are in the...
Suppose you have a 4-sided die with t1= 0.4, t2= 0.2, t3= 0.1, and t4 =...
Suppose you have a 4-sided die with t1= 0.4, t2= 0.2, t3= 0.1, and t4 = 0.3, where tj is the probability that side j will show up when you roll the die. If you roll the die 5 times, what is the probability that you will get 1 of side 1, 3 of side 2, and 1 of side 4?
Suppose we have a regression model with 3 independent variables and an R2 value of 0.65...
Suppose we have a regression model with 3 independent variables and an R2 value of 0.65 and an adjusted R2 value of 0.61. When we add a fourth independent variable, the new R2 value is 0.73 and the new adjusted R2 value is 0.54. What can we conclude about this newly added independent variable? Group of answer choices The new independent variable improves our model because R-squared increased The new independent variable improves our model because the adjusted R-squared value...
Show that the following statement holds: i) for each simple module M, we have rad M...
Show that the following statement holds: i) for each simple module M, we have rad M = 0 II) for each module V and any maximal submodule J of V, rad (V/J) = 0
Suppose we have six $1 bills that we are going to hand out to 3 of...
Suppose we have six $1 bills that we are going to hand out to 3 of our friends. How many ways can we do that? My teachers solution is 8 choose 2 using the but I thought the answer would be 3^6 since each dollar has the option of going to 3 different people.
Suppose that we have the following auction scheme. There are two bidders, and an item to...
Suppose that we have the following auction scheme. There are two bidders, and an item to be allocated to them. Each bidder submits a bid. The highest bidder gets the good, but both bidders pay their bids. Consider the case in which bidder 1 values the item at 3, while bidder 2 values the item at 5; this is commonly known. Each bidder can only submit one of three bids: 0, 1 or 2. If player i bids more than...
I recently did a lab where we used a Styrofoam coffee cup calorimeter to determine the...
I recently did a lab where we used a Styrofoam coffee cup calorimeter to determine the specific heat of an unknown metal. We just determined our "calorimeter constant." We now have to re-do all of our prior calculations to include this new constant. I may have written down the wrong equation, so could someone show me an example given the following information? Heat capacity of calorimeter: 41.6 J/gC Mass of metal: 43.0760g Mass of water: 20.6314g Delta T water: 21.1...
AHW2) Hello I have an agile software development methodology that is proposed by the combining the...
AHW2) Hello I have an agile software development methodology that is proposed by the combining the two other agile development methodologies, my question is how can I draw its process model that describe it entirely(as drawing graphs). The description of the new proposed methodology is given below: 1. The new Agile methodology is "Feature and Test Driven Development". 2. Feature Driven Development (FDD) is an iterative and incremental Agile methods for developing software. This is client centric pragmatic Software process....
Suppose we have the following 25 residuals, 8, ?5, 7, 1, ?3, ?3, 3, ?5, 1,...
Suppose we have the following 25 residuals, 8, ?5, 7, 1, ?3, ?3, 3, ?5, 1, 9, 8, ?5, 7, 1, ?3, ?3, 3, ?5, 1, 9, 8, ?5, 7, 1, ?3 from the linear model: y = ?0 + ?1x1 + ?2x2 + . (a) Please use Durbin-Watson statistic to test H0 : ? = 0 at 5% level of significance. (b) Please use run test to examine if there are too many runs at 5% level of significance.
Suppose that we have the following supply and demand functions for gumboots in a small, open...
Suppose that we have the following supply and demand functions for gumboots in a small, open economy called Finland: QS=-30+2p QD =60–p where QS and QD are measured in 1000’s of pairs of gumboots. The world price of gumboots equals $25. Which of the following is TRUE? 1) The price of gumboots in Finland is $30 per pair. Finland will neither export nor import. 2) The price of gumboots in Finland is $25 per pair. Finland will import 15,000 pairs...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT