title: replacing use of one def with other def in llvm IR
body: <p>I have following IR:</p>
  
  <pre><code>%2 = load i32* %b, align 4
  store i32 %2, i32* %a, align 4
  %3 = load i32* %a, align 4
  store i32 %3, i32* %b, align 4
  </code></pre>
  
  <p>which is essentially</p>
  
  <pre><code>a=b; b=a;
  </code></pre>
  
  <p>Now, after copy propagation, i want something like:</p>
  
  <pre><code>a=b; b=b;
  </code></pre>
  
  <p>So, I do this:</p>
  
  <pre><code>i-&gt;setOperand(0,op1)  //op1 points to %b, i points to  [%3 = load i32* %a, align 4]
  i-&gt;replaceUsesOfWith(op2,op1); //op2 points to %a
  </code></pre>
  
  <p>Doing this, I get into infinite loop for above IR. So I have a feeling that there is some problem with removing i from uses of op1 and adding i to uses of op2.
  However, code runs fine for something like:</p>
  
  <pre><code>a=b; c=a; 
  </code></pre>
  
  <p>after transformation I get: <code>a=b; c=b;</code></p>