Compiler engineer Interview Questions
94
Compiler Engineer interview questions shared by candidates
Assume your assembly language includes ONLY the following instructions: 'inc REG': increments a given register by one. 'dec REG': decrement a given register by one. 'jnz LABEL': jumps to a given LABEL if the previous instruction's result was not zero. 'HALT': stops running. Task: A and B registers hold non-negative values. The program should calculate the value of |A-B| and locate the result in C. In addition, the language holds registers C,D,...,Z, which you can assume are initialized at program start to zero.
2 Answers↳
Not well
↳
sub_A: DEC A JNZ sub_B INC D JNZ A_reached_zero sub_B: DEC B JNZ sub_A A_grater: INC C DEC A JNZ A_greater HALT A_reached_zero: DEC B JNZ B_greater HALT B_greater: INC C DEC B JNZ B_greater HALT Less

Optimize this code (like what compiler would reconstruct an equivalent source code as): int fn (int a, int b) { int sum = 0; for(int i=4*a;i>0;i--) { sum+=b*i*i; } return sum; }
2 Answers



The performance of a program is slower than the same program before the backend of the compiler has changed. What direction would you look into this issue and solve it?
1 Answers↳
I will utilize tools to find out hotspots in the target program. Then disassemble some particular hotspots, to see whether it's regard to loop, and CPU pipeline. Then try to unroll the loop, or rearrange the policy of the CG backend. Less

How would you narrow down bugs, if you came in one day and found 10 new failures with your run?
1 Answers↳
Check the environment first, so see if anything has changed.

Implement the next function in C (value can be also negative): char * itoa (int value, char * str);
1 Answers↳
Very good

Given a 100 story building and 2 cell phones to test, a company asks you to find the minimum floor at which you can drop a phone until it breaks. Do this in the minimum number of tests.
1 Answers↳
Drop the first cellphone every 10 stories and then use the second cell phone every story starting from the previous 10 stories. It is an optimization problem minimizing the sum of major and minor steps taken for the worst possible case (e.g. phone breaks at 100th floor). Less

Give an example of a time you solved a technical problem
1 Answers↳
Finding bugs in 3rd party libraries