Hi all!<br><br>While playing with LLVM, I've found a weird behavior in mem2reg pass.<br><br>When optimizing single stores, undefined value is placed before any load preceding the store (based on basicblock's ordering and simple dominator analysis, if I remember correctly).<br><br>This is the line that is responsible for the behavior: (LLVM9 does the same)<br><br><a href="https://llvm.org/doxygen/PromoteMemoryToRegister_8cpp_source.html#l00629">https://llvm.org/doxygen/PromoteMemoryToRegister_8cpp_source.html#l00629</a><br><br>A problem arises, and I am not sure if it is really a problem or just weird C-compliant behavior.<br><br>int a; // or, equally, int a=0;<br><br>int main(){<br>  int b;<br>  if (b) // (*)<br>    b=a;<br>  if (b)<br>    printf("This will be called");<br>}<br><br>The first load of variable b, before the single store (the first branching) is replaced by undef, so the second branch will be replaced by a phi node, if the (*) branch is taken, the value is 0, else undef.<br><br>I'm concerned that this is an LLVM bug.<br><br>Reproduction:<br><br>clang -S -emit-llvm test.c<br>opt -mem2reg test.ll<br><br>I'm not at the computer right now, so I cannot show the exact generated code.<br><br>Radnai László<br>