CONSTANT PROPAGATION (DATA FLOW ANALYSIS) MCQs—Compiler Design
CONSTANT PROPAGATION (DATA FLOW ANALYSIS) — MCQs
1.
Constant propagation is a part of which phase in a compiler?
A) Lexical Analysis
B) Parsing
C) Intermediate Code Optimization
D) Code Generation
✅ Answer: C) Intermediate Code Optimization
Solution:
Constant propagation is a data flow optimization that replaces variables with known constants in the intermediate code to improve performance before code generation.
2.
Which of the following statements best defines constant propagation?
A) Replacing variable names with temporary registers
B) Replacing variables whose values are constant with those constants
C) Removing unused variables from symbol table
D) Eliminating loops with fixed bounds
✅ Answer: B) Replacing variables whose values are constant with those constants
Solution:
The goal is to simplify computations by substituting constant values directly where possible.
3.
In constant propagation, if x = 10; y = x + 5;, then y becomes:
A) x + 5
B) 10 + 5
C) x
D) 5 + x
✅ Answer: B) 10 + 5
Solution:
Since x is constant, y = 10 + 5 = 15 after propagation and constant folding.
4.
Constant propagation is based on which analysis technique?
A) Syntax analysis
B) Data flow analysis
C) Control flow analysis
D) Register allocation
✅ Answer: B) Data flow analysis
Solution:
It uses data flow equations to track constant values across program points.
5.
Which of the following cannot be replaced by constant propagation?
A) Variables with known constants
B) Variables computed from unknown inputs
C) Compile-time constants
D) Simple arithmetic constants
✅ Answer: B) Variables computed from unknown inputs
Solution:
If the value of a variable depends on runtime input, it cannot be replaced during compilation.
6.
In constant propagation, which information is propagated?
A) Type information
B) Register allocation
C) Known constant values
D) Symbol names
✅ Answer: C) Known constant values
Solution:
The compiler maintains value maps to propagate constants across program points.
7.
If a = 5; b = a; c = b + 2;, after constant propagation, c becomes:
A) a + 2
B) b + 2
C) 7
D) c
✅ Answer: C) 7
Solution:a and b both are constants equal to 5, so c = 7.
8.
Constant propagation requires that the variable’s value is:
A) Constant in one basic block
B) Constant across all paths reaching a point
C) Constant in only one loop iteration
D) Variable but known
✅ Answer: B) Constant across all paths reaching a point
Solution:
The value must be the same along all possible execution paths for it to be propagated safely.
9.
Which of these statements about constant propagation is false?
A) It uses a lattice model
B) It can be done interprocedurally
C) It may require control flow graph
D) It introduces runtime overhead
✅ Answer: D) It introduces runtime overhead
Solution:
Constant propagation reduces runtime computation; it doesn’t increase it.
10.
The constant propagation problem can be represented as:
A) Reaching definitions problem
B) Available expressions problem
C) Constant value problem
D) Live variable problem
✅ Answer: A) Reaching definitions problem
Solution:
It relies on identifying definitions that reach a program point with unique constant assignments.
11.
If if (x > 0) y = 10; else y = 20; z = y + 2; — constant propagation for z is possible only when:
A) x is known
B) y is global
C) z is loop invariant
D) Control flow is ignored
✅ Answer: A) x is known
Solution:
Because y depends on the condition of x, only if x is constant can we determine y’s constant value.
12.
Constant propagation is most effective when:
A) Branches are independent
B) Control flow is linear
C) Loops are nested
D) Recursion is heavy
✅ Answer: B) Control flow is linear
Solution:
Linear control flow avoids multiple reaching definitions, making propagation easier.
13.
Which data flow direction is used for constant propagation?
A) Backward
B) Forward
C) Bidirectional
D) None
✅ Answer: B) Forward
Solution:
Constant propagation computes known constant values by flowing information forward through the control flow graph.
14.
The lattice for constant propagation includes elements:
A) {Top, Constants, Bottom}
B) {Constant, Variable, Undefined}
C) {Reachable, Unreachable}
D) {Known, Unknown, Invalid}
✅ Answer: A) {Top, Constants, Bottom}
Solution:Top = Unknown, Constant = specific value, Bottom = conflicting values.
15.
In data flow analysis, the “meet” operation in constant propagation is:
A) Union
B) Intersection
C) Greatest lower bound (GLB)
D) Least upper bound (LUB)
✅ Answer: C) Greatest lower bound (GLB)
Solution:
For constant propagation, the meet operator combines paths conservatively using the intersection of possible constant values.
16.
Which of these can hinder constant propagation?
A) Function calls with side effects
B) Pure functions
C) Constant initialization
D) Local variables
✅ Answer: A) Function calls with side effects
Solution:
Functions that modify variables externally make constant propagation unsafe.
17.
In a control flow graph, a join node with conflicting constants for a variable leads to:
A) Propagation of average value
B) Marking variable as “unknown”
C) Ignoring the variable
D) Propagating last assigned constant
✅ Answer: B) Marking variable as “unknown”
Solution:
When different constants reach a point, it’s marked as “Top” (unknown).
18.
Constant propagation and constant folding differ in that:
A) Folding evaluates constants; propagation substitutes them
B) Both are same
C) Folding is dynamic; propagation is static
D) Propagation is machine-dependent
✅ Answer: A) Folding evaluates constants; propagation substitutes them
Solution:
Constant folding performs computation, while propagation replaces variable references.
19.
Constant propagation may increase opportunities for:
A) Dead code elimination
B) Loop unrolling
C) Function inlining
D) Register allocation
✅ Answer: A) Dead code elimination
Solution:
Once constants are substituted, unused computations become easier to detect.
20.
Which of the following statements is true?
A) Constant propagation requires inter-block data flow analysis
B) Constant propagation ignores control flow
C) Constant propagation is undecidable
D) Constant propagation works only for loops
✅ Answer: A) Constant propagation requires inter-block data flow analysis
Solution:
It tracks constant values across basic blocks via control flow edges.
21.
If variable x can take both 5 and 8 on different paths, its lattice value at merge point is:
A) 5
B) 8
C) ⊤ (unknown)
D) ⊥ (conflict)
✅ Answer: C) ⊤ (unknown)
Solution:
Conflicting constants merge into the “unknown” top value.
22.
A compiler uses constant propagation to:
A) Improve code readability
B) Reduce runtime computation
C) Increase symbol table size
D) Delay evaluation
✅ Answer: B) Reduce runtime computation
Solution:
It replaces expressions with constants, saving computation during execution.
23.
Which optimization is often performed after constant propagation?
A) Loop invariant code motion
B) Common subexpression elimination
C) Constant folding
D) Strength reduction
✅ Answer: C) Constant folding
Solution:
Once constants are substituted, expressions can be folded into literal results.
24.
If a = 3; b = a + 2; c = b * 4;, then constant propagation yields:
A) b = 3 + 2; c = 5 * 4
B) b = 5; c = 20
C) b = a + 2; c = b * 4
D) c = a * 4
✅ Answer: B) b = 5; c = 20
Solution:a, b are constants → replace and fold sequentially.
25.
The correctness of constant propagation depends on:
A) Static single assignment form (SSA)
B) Register allocation
C) Target machine architecture
D) Stack management
✅ Answer: A) Static single assignment form (SSA)
Solution:
SSA simplifies constant propagation because each variable has exactly one definition.
CONSTANT PROPAGATION (DATA FLOW ANALYSIS)
26.
Which of the following forms is most suitable for constant propagation?
A) Three-address code
B) Assembly language
C) High-level source code
D) Machine code
✅ Answer: A) Three-address code
Solution:
Constant propagation is typically applied on intermediate representation (IR) such as three-address code since it explicitly represents assignments and computations.
27.
The result of constant propagation is mainly used by:
A) Parser
B) Optimizer
C) Lexer
D) Code linker
✅ Answer: B) Optimizer
Solution:
Constant propagation is a local/global optimization technique performed in the optimization phase of a compiler.
28.
Which of the following pairs are closely related optimizations?
A) Loop unrolling and constant propagation
B) Constant propagation and constant folding
C) Dead code elimination and loop optimization
D) Copy propagation and register allocation
✅ Answer: B) Constant propagation and constant folding
Solution:
Constant propagation substitutes constant values; constant folding evaluates constant expressions.
29.
Which lattice element represents “no constant information” in constant propagation?
A) Bottom (⊥)
B) Top (⊤)
C) Null
D) Undefined
✅ Answer: B) Top (⊤)
Solution:⊤ denotes the “unknown” or uninitialized constant information.
30.
In constant propagation, the meet operator at control flow joins uses:
A) Maximum constant value
B) Intersection of possible constants
C) Summation of constants
D) Assignment override
✅ Answer: B) Intersection of possible constants
Solution:
Only constants that are identical across all paths can be propagated further.
31.
If a variable is assigned constant 5 in one path and not assigned at all in another, its value at merge point is:
A) 5
B) Unknown (⊤)
C) 0
D) Not propagated
✅ Answer: B) Unknown (⊤)
Solution:
In absence of a consistent definition across all paths, the result is unknown.
32.
Constant propagation cannot propagate values across:
A) Function boundaries
B) Basic blocks
C) Single instructions
D) Local scopes
✅ Answer: A) Function boundaries
Solution:
Unless interprocedural analysis is used, constants are not propagated across function calls.
33.
Which among the following is not a prerequisite for constant propagation?
A) Knowledge of control flow graph
B) Identification of reaching definitions
C) Liveness analysis
D) Lattice design
✅ Answer: C) Liveness analysis
Solution:
Constant propagation requires data flow equations, not liveness information.
34.
The advantage of constant propagation is:
A) Faster parsing
B) Fewer runtime computations
C) Smaller symbol tables
D) Less memory usage
✅ Answer: B) Fewer runtime computations
Solution:
Replacing constants at compile time reduces arithmetic operations during execution.
35.
Which of the following examples shows an unsafe propagation?
A) x = 3; if(cond) x = 5; y = x;
B) x = 4; y = x + 2;
C) a = 2; b = a * 3;
D) p = 10; q = p;
✅ Answer: A) x = 3; if(cond) x = 5; y = x;
Solution:
Since x can be 3 or 5 depending on the condition, y cannot be propagated with a constant.
36.
Constant propagation assumes variables are:
A) Mutable but predictable
B) Immutable
C) Undefined
D) Non-deterministic
✅ Answer: B) Immutable
Solution:
Only variables that don’t change during execution within a path can be safely propagated.
37.
In SSA (Static Single Assignment), constant propagation is easier because:
A) There are no loops
B) Each variable has a single definition
C) Variables are dynamically typed
D) Control flow is linear
✅ Answer: B) Each variable has a single definition
Solution:
SSA removes ambiguity of multiple definitions per variable, simplifying constant analysis.
38.
The equation for constant propagation data flow is:
A) OUT[n] = f(IN[n])
B) IN[n] = f(OUT[n])
C) OUT[n] = IN[n] ∩ DEF[n]
D) IN[n] = OUT[n] ∪ DEF[n]
✅ Answer: A) OUT[n] = f(IN[n])
Solution:
Constant propagation is a forward analysis, thus data flows from IN to OUT.
39.
Which of the following does constant propagation not require?
A) Flow graph
B) Use-def chains
C) Instruction reordering
D) Data flow equations
✅ Answer: C) Instruction reordering
Solution:
Reordering is part of code scheduling, not constant propagation.
40.
If x = 2; while(x < 5) { x = x + 1; } print(x);
After propagation, what value can be printed?
A) 2
B) 5
C) Unknown
D) Depends on runtime
✅ Answer: C) Unknown
Solution:
Since x changes during loop execution, constant propagation can’t determine its final value.
41.
Constant propagation replaces variables with:
A) Literals
B) Registers
C) Memory addresses
D) Temporary labels
✅ Answer: A) Literals
Solution:
The variable references are substituted with constant literal values.
42.
In a control flow graph, propagation stops when:
A) The value changes
B) The value becomes constant
C) The variable is reassigned with unknown value
D) There are no edges
✅ Answer: C) The variable is reassigned with unknown value
Solution:
A new assignment with a non-constant breaks previous constant information.
43.
Constant propagation is considered a:
A) Peephole optimization
B) Global optimization
C) Register allocation
D) Parsing enhancement
✅ Answer: B) Global optimization
Solution:
It operates across basic blocks, depending on global control flow.
44.
Which analysis uses constant propagation to remove redundant computations?
A) Dead code elimination
B) Loop optimization
C) Constant folding
D) Common subexpression elimination
✅ Answer: D) Common subexpression elimination
Solution:
After constant propagation, redundant computations can be identified more easily.
45.
If variable v’s lattice value is bottom (⊥), it implies:
A) Value not yet determined
B) Value conflicting across paths
C) Constant value
D) Unreachable code
✅ Answer: D) Unreachable code
Solution:
In constant propagation lattices, ⊥ represents unreachable or uninitialized regions.
46.
In the equation z = x + y, if both x and y are constants, propagation can be followed by:
A) Loop optimization
B) Constant folding
C) Dead code removal
D) Register renaming
✅ Answer: B) Constant folding
Solution:
After propagation, arithmetic on constants can be computed at compile time.
47.
Constant propagation may fail if:
A) Program uses recursion
B) Variable has dynamic value
C) Variable is constant in all paths
D) Value assigned at compile time
✅ Answer: B) Variable has dynamic value
Solution:
Dynamic or input-dependent variables cannot be propagated safely.
48.
Which data structure is used to store constant information during propagation?
A) Symbol table
B) Constant map
C) Stack
D) Linked list
✅ Answer: B) Constant map
Solution:
Each variable maps to a constant value (if known) in a table during analysis.
49.
The transfer function in constant propagation is:
A) Monotone
B) Non-monotone
C) Random
D) Non-deterministic
✅ Answer: A) Monotone
Solution:
Monotonicity ensures convergence in data flow analysis.
50.
The constant propagation analysis terminates when:
A) No variable changes its lattice value
B) All constants are found
C) No constants exist
D) All loops end
✅ Answer: A) No variable changes its lattice value
Solution:
Convergence is achieved when successive iterations yield no change.
51.
Which of these optimization phases can directly benefit from constant propagation?
A) Register allocation
B) Dead code elimination
C) Instruction selection
D) Code emission
✅ Answer: B) Dead code elimination
Solution:
Propagated constants expose branches or conditions that are statically true/false.
52.
Constant propagation is guaranteed to converge because:
A) Lattice height is finite
B) Variables are constant
C) Code is static
D) There is only one path
✅ Answer: A) Lattice height is finite
Solution:
Finite lattice height and monotone transfer functions ensure termination.
53.
Constant propagation can be extended interprocedurally using:
A) Call graph analysis
B) SSA form
C) Inline substitution
D) Copy propagation
✅ Answer: A) Call graph analysis
Solution:
It requires understanding of inter-function calling relationships.
54.
Which constant propagation issue may arise due to side effects?
A) Incorrect substitution
B) Infinite loop
C) Register spilling
D) Deadlock
✅ Answer: A) Incorrect substitution
Solution:
Side effects may alter variable values, making earlier propagation invalid.
55.
In SSA, constant propagation mainly occurs at:
A) Phi nodes
B) Entry blocks
C) Exit blocks
D) Return statements
✅ Answer: A) Phi nodes
Solution:
Phi functions merge constants from different paths, determining whether the variable remains constant.
56.
The value lattice used for constant propagation contains:
A) Integer constants only
B) All possible constant values plus ⊤ and ⊥
C) Boolean constants only
D) Floating constants only
✅ Answer: B) All possible constant values plus ⊤ and ⊥
Solution:
This allows representing every possible constant and unknown situations.
57.
If a loop variable changes each iteration, constant propagation:
A) Applies partially
B) Not applicable inside the loop
C) Propagates initial value
D) Fails to analyze
✅ Answer: B) Not applicable inside the loop
Solution:
Variable reassignment in each iteration breaks constantness.
58.
The correctness of constant propagation depends on:
A) Conservative analysis
B) Aggressive optimization
C) Dynamic profiling
D) Runtime feedback
✅ Answer: A) Conservative analysis
Solution:
The algorithm must never assume a constant when multiple values are possible.
59.
Which transformation may occur after constant propagation and folding?
A) Unreachable code removal
B) Loop unrolling
C) Function duplication
D) Variable renaming
✅ Answer: A) Unreachable code removal
Solution:
Branches with constant false conditions can be eliminated.
60.
If a program segment has no loops, constant propagation:
A) Always converges faster
B) Becomes redundant
C) Requires backward analysis
D) Needs iterative refinement
✅ Answer: A) Always converges faster
Solution:
Linear flow ensures fewer iterations to reach a fixpoint.
61.
Constant propagation handles expressions involving:
A) Constants only
B) Constants and constant variables
C) Variables only
D) Input-dependent variables
✅ Answer: B) Constants and constant variables
Solution:
The expressions must contain known constant operands.
62.
In lattice theory for constant propagation, ⊤ means:
A) Variable has multiple constant values
B) Variable uninitialized
C) Variable known constant
D) Variable unused
✅ Answer: A) Variable has multiple constant values
Solution:
⊤ implies conflicting definitions from different paths.
63.
Which of the following optimizations might enable new constant propagation opportunities?
A) Copy propagation
B) Loop interchange
C) Dead store elimination
D) Function inlining
✅ Answer: D) Function inlining
Solution:
Inlining exposes constants across function boundaries.
64.
Which of these is most accurate about constant propagation’s complexity?
A) Polynomial
B) Exponential
C) Logarithmic
D) NP-complete
✅ Answer: A) Polynomial
Solution:
Data flow problems such as constant propagation are solvable in polynomial time.
65.
Which algorithm framework does constant propagation use?
A) Iterative data flow analysis
B) Lexical analysis
C) Backtracking search
D) CFG reduction
✅ Answer: A) Iterative data flow analysis
Solution:
It iteratively refines values until a stable solution is found.
66.
If x = 4; y = x * 2; z = y - 3;, after propagation:
A) z = (4 * 2) - 3
B) z = 5
C) z = 8 - 3
D) Both A and C
✅ Answer: D) Both A and C
Solution:
Constants substitute and simplify step-by-step before folding.
67.
In constant propagation, when is a phi node marked as constant?
A) All incoming values are same constants
B) One incoming value constant
C) All paths differ
D) At loop headers
✅ Answer: A) All incoming values are same constants
Solution:
Phi merges must agree to retain constant status.
68.
If all paths to a block assign variable a = 2, its lattice value becomes:
A) 2
B) ⊤
C) ⊥
D) Unknown
✅ Answer: A) 2
Solution:
Same constant along all paths → safe to propagate.
69.
Which of these is true for constant propagation?
A) It’s safe but not always profitable
B) It’s unsafe in SSA
C) It reduces code size always
D) It increases runtime complexity
✅ Answer: A) It’s safe but not always profitable
Solution:
It guarantees correctness but may not yield large runtime gains in all cases.
70.
In a compiler, constant propagation is done before:
A) Register allocation
B) Code emission
C) Instruction scheduling
D) All of these
✅ Answer: D) All of these
Solution:
Propagation occurs during optimization before final code generation phases.
71.
If two different constants reach a point, result is:
A) Any of them
B) Unknown (⊤)
C) Minimum of two
D) Average
✅ Answer: B) Unknown (⊤)
Solution:
Conflicting constants mark the variable as not constant.
72.
Which of the following data flow equations describes propagation?
A) OUT[B] = f_B(IN[B])
B) IN[B] = f_B(OUT[B])
C) OUT[B] = IN[B] ∪ GEN[B]
D) IN[B] = OUT[B] − KILL[B]
✅ Answer: A) OUT[B] = f_B(IN[B])
Solution:
Forward propagation uses transfer function from IN to OUT sets.
73.
Constant propagation cannot resolve:
A) Compile-time constants
B) Runtime-dependent expressions
C) Constant initializations
D) Simple arithmetic
✅ Answer: B) Runtime-dependent expressions
Solution:
Values determined only at runtime are beyond compile-time analysis.
74.
The “meet” operator in constant propagation is usually:
A) Equality check
B) Intersection
C) Union
D) Addition
✅ Answer: B) Intersection
Solution:
Only identical constants across paths are preserved.
75.
In SSA, constant propagation iterates until:
A) No phi changes
B) All constants identified
C) Control flow stable
D) All loops terminate
✅ Answer: A) No phi changes
Solution:
Convergence is achieved when no variable’s lattice value changes further.
76.
Which approach allows constant propagation to handle arrays partially?
A) Index range analysis
B) Pointer alias analysis
C) Interval analysis
D) Symbol table merging
✅ Answer: C) Interval analysis
Solution:
Range-based analysis can estimate constant bounds for array indices.
77.
If flag = true, then if(flag) a = 5; else a = 7;
After constant propagation:
A) a = 5
B) a = flag ? 5 : 7
C) a = 7
D) No change
✅ Answer: A) a = 5
Solution:
Condition known → true branch constant propagated.
78.
Constant propagation interacts closely with:
A) Dead code elimination
B) Common subexpression elimination
C) Both A and B
D) None
✅ Answer: C) Both A and B
Solution:
After constants are propagated, many redundant computations become dead or common.
79.
Which property ensures termination of data flow iterations in constant propagation?
A) Finite lattice height
B) Bounded loops
C) Static typing
D) Constant domain size
✅ Answer: A) Finite lattice height
Solution:
Finite height prevents infinite oscillations in lattice values.
80.
Constant propagation simplifies conditional branches when:
A) Condition variables are constants
B) Loops exist
C) Multiple conditions merge
D) Nested ifs exist
✅ Answer: A) Condition variables are constants
Solution:
If condition evaluates to true/false at
compile time, one branch becomes dead.
81.
Which form simplifies implementation of constant propagation most?
A) SSA
B) Control flow graph
C) Parse tree
D) AST
✅ Answer: A) SSA
Solution:
SSA form ensures one assignment per variable, simplifying propagation logic.
82.
Constant propagation helps reveal:
A) Unreachable code
B) Memory leaks
C) Synchronization issues
D) Data races
✅ Answer: A) Unreachable code
Solution:
Conditions evaluating to false make subsequent branches unreachable.
83.
In forward data flow analysis for constant propagation, initialization is:
A) All variables set to ⊤
B) All variables set to ⊥
C) All constants set to 0
D) None
✅ Answer: A) All variables set to ⊤
Solution:
Initially, all constants are unknown until analysis refines them.
84.
If variable x is defined in two blocks with different constants, then at merge:
A) x = ⊤
B) x = 0
C) x = average
D) x = any constant
✅ Answer: A) x = ⊤
Solution:
Conflicting constants → unknown.
85.
Which optimization increases constant propagation scope?
A) Function inlining
B) Loop fusion
C) Register spilling
D) Code duplication
✅ Answer: A) Function inlining
Solution:
Inlining exposes constants defined inside called functions.
86.
A phi node x = φ(3,3) represents:
A) x = 3
B) x = ⊤
C) x = ⊥
D) x = 0
✅ Answer: A) x = 3
Solution:
All incoming values identical → safe constant.
87.
When a phi node merges constants 5 and 8, it results in:
A) 5
B) 8
C) ⊤
D) Average
✅ Answer: C) ⊤
Solution:
Different incoming values → unknown result.
88.
Which pass commonly implements constant propagation?
A) Data flow solver
B) Peephole optimizer
C) Register allocator
D) Linker
✅ Answer: A) Data flow solver
Solution:
It uses iterative forward data flow equations.
89.
Constant propagation aids in:
A) Branch pruning
B) Memory allocation
C) Parsing speed
D) Token reduction
✅ Answer: A) Branch pruning
Solution:
Constant conditions simplify control flow, removing unreachable branches.
90.
A conservative constant propagation ensures:
A) No incorrect constant assumptions
B) Maximal optimization
C) All variables constant
D) Fewer iterations
✅ Answer: A) No incorrect constant assumptions
Solution:
It avoids unsafe assumptions, preserving program semantics.
91.
If while(false) is detected, compiler:
A) Removes loop body
B) Executes once
C) Marks unknown
D) Converts to conditional
✅ Answer: A) Removes loop body
Solution:
Constant propagation + dead code elimination remove such loops.
92.
Constant propagation combined with folding may transform:
A) x = 2 + 3 → x = 5
B) x = 2 * y → x = 2 * y
C) x = y → x = y
D) x = 3 / z → unchanged
✅ Answer: A) x = 2 + 3 → x = 5
Solution:
Substitution and evaluation reduce expression to a literal constant.
93.
Which variable is eligible for propagation?
A) Defined once, used multiple times
B) Defined multiple times
C) Modified by I/O operation
D) Dependent on user input
✅ Answer: A) Defined once, used multiple times
Solution:
Single assignment with constant value → safe for propagation.
94.
In data flow equations, convergence occurs due to:
A) Finite lattice + monotone functions
B) Dynamic profiling
C) Loop unrolling
D) Register reuse
✅ Answer: A) Finite lattice + monotone functions
Solution:
Mathematical property guarantees analysis stability.
95.
Constant propagation identifies:
A) Compile-time evaluable expressions
B) Runtime constants
C) Variable aliases
D) Stack size
✅ Answer: A) Compile-time evaluable expressions
Solution:
Substitutes expressions whose results are determinable at compile time.
96.
Which of the following is not true for constant propagation?
A) It’s forward analysis
B) It’s monotone
C) It uses control flow
D) It depends on target architecture
✅ Answer: D) It depends on target architecture
Solution:
Constant propagation is architecture-independent compiler optimization.
97.
Constant propagation may remove:
A) Dead loops
B) Constant branches
C) Static conditions
D) All of these
✅ Answer: D) All of these
Solution:
All redundant code segments based on constant evaluation can be eliminated.
98.
Constant propagation is sometimes known as:
A) Constant substitution
B) Constant scheduling
C) Constant allocation
D) Constant parsing
✅ Answer: A) Constant substitution
Solution:
Because variables are replaced (substituted) by constant values.
99.
After constant propagation, compiler may detect:
A) Simplified expressions
B) Fewer temporary variables
C) Dead branches
D) All of these
✅ Answer: D) All of these
Solution:
Propagated constants simplify expressions, reduce temporaries, and expose dead code.
100.
Constant propagation in compilers aims to:
A) Improve execution efficiency
B) Reduce parsing errors
C) Simplify syntax trees
D) Improve type checking
✅ Answer: A) Improve execution efficiency
Solution:
By eliminating runtime computations of constant expressions, it enhances runtime performance.