The attached patched takes a sequence like:<div><div> %neg = xor i32 %A, -1</div><div> %shl = shl i32 1, %B</div><div> %and = and i32 %shl, %neg</div><div> %cmp = icmp ne i32 %and, 0</div></div><div><br></div><div>and turns it into:</div>

<div><div> %shl = shl i32 1, %B<br></div><div> %and = and i32 %shl, %A</div><div> %cmp = icmp eq i32 %and, 0</div></div><div><br></div><div>The patch includes a test case that exercises this transform.</div><div><br></div>
<div>Examples of frontend code that could generate sequence 1 is:</div><div><br></div><div>bool fun1(unsigned A, unsigned B) { return ~A & (1 << B); }</div><div><br></div><div>An example of sequence 2 is:</div><div>
bool fun2(unsigned A, unsigned B) { return !(A & (1 << B)); }<br></div><div><br></div><div>With this patch, they would have the same IR.</div>