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...
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...
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....
I am having trouble creating a procedure to use to identify five unknown solutions we will...
I am having trouble creating a procedure to use to identify five unknown solutions we will be given in chem lab. The five solutions will be an acid, a base, a chloride salt, a nitrate salt, and a sodium salt. I have to come up with steps to determine which compound is in each category. Only one will be in each solution. Acid- HCl, HNO3, H2SO4 Base - NaOH, NH3, Na2S Chloride Salt - NaCl, BaCl2, CuCl Nitrate Salt -...
Hello Expert, I am stuck on this assignment and can't get my code to run. I...
Hello Expert, I am stuck on this assignment and can't get my code to run. I would really appreciate it if anyone can help me. Assignment Requirements: Your software development company wants to continue developing and enhancing a software for internal use. For this week's assignment, it is required to read from a JSON application file (data.json) containing employee information. You will not use LINQ for this task. Your tasks include: Convert the previously created data.txt file into a JSON...
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...