<div dir="ltr">Here's a minimum reproducing example (attached and inline below):<div><br></div><div>define i32 @foo(i32*) {</div><div>entry:</div><div>  %1 = load i32, i32* %0</div><div>  %2 = icmp eq i32 %1, 3</div><div>  call void @llvm.assume(i1 %2)</div><div>  %3 = load i32, i32* %0</div><div><div>  ret i32 %3</div><div>}</div></div><div><br></div><div>Both -early-cse and -gvn independently simplify this IR to:</div><div><br></div><div><div>define i32 @foo(i32*) {</div><div>entry:</div><div>  %1 = load i32, i32* %0</div><div>  ret i32 %1</div><div>}</div></div><div><br></div><div>Whereas I think it would be more correct to simplify it to:</div><div><br></div><div><div>define i32 @foo(i32*) {</div><div>entry:</div><div>  %1 = load i32, i32* %0</div><div>  %2 = icmp eq i32 %1, 3</div><div>  call void @llvm.assume(i1 %2)</div><div>  ret i32 %1</div><div>}</div></div><div><br></div><div>And then:</div><div><br></div><div><div>define i32 @foo(i32*) {</div><div>entry:</div></div><div>  ret i32 3</div><div>}</div><div><br></div><div>Both -early-cse and -gvn appear capable of this final optimization, but get stuck doing the wrong thing when given the initial code with the redundant load.</div><div><br></div><div>v/r,</div><div>Josh</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 10, 2016 at 11:42 AM, Josh Klontz <span dir="ltr"><<a href="mailto:josh.klontz@gmail.com" target="_blank">josh.klontz@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">As of llvm 3.8, the early CSE pass seems to remove llvm.assume intrinsics. Is this the expected behavior?<div><br></div><div>I've attached as small-ish example of this happening in my production code.<div><br></div><div>    $ opt -early-cse before-early-cse.ll -S > after-early-cse.ll</div><div><br></div><div>Note the use of the assume intrinsic indicating that the loaded value %channels equals 3. In a later pass I replace the load instruction with the constant value. This approach worked in llvm 3.7. I can solve the issue by moving my pass before early CSE if need be.</div><div><br></div><div>v/r,</div><div>Josh</div>







</div></div>
</blockquote></div><br></div>