Machine-translated by Google. Questions are authored in English.
Top

Discussion

Common subexpression elimination requires the compiler to establish that

  • A.the expression appears at least three times in the same procedure
  • B.the expression involves only constants known at compile time
  • C.the target machine has enough registers to hold the saved value
  • D.the operands of the repeated expression have not changed in between

Answer: D

Correct answer: the operands of the repeated expression have not changed in between

Reusing a computed value is safe only if the value is still the same, so the compiler must establish that nothing between the two occurrences assigned to any operand.

That is a data-flow question, and an assignment through a pointer or a call to a function that might modify a variable will defeat it - which is why aliasing makes the analysis conservative. The number of occurrences is irrelevant, constants are the domain of folding, and register pressure affects whether the saving is worth taking rather than whether it is legal.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.