google / souper

A superoptimizer for LLVM IR
Apache License 2.0
2.17k stars 170 forks source link

Set available=false for overflow instructions when parsing #845

Closed zhengyang92 closed 3 years ago

zhengyang92 commented 3 years ago

Note with this patch, we still can't get the result we want for the case

%0:i32 = var
%1:i32 = var
%2:i33 = ssub.with.overflow %0, %1 (hasExternalUses)
%3:i32 = extractvalue %2, 0:i32 (hasExternalUses)
%4:i1 = ule %3, 31:i32
pc %4 1:i1
%5:i32 = subnw 31:i32, %3
%6:i32 = lshr 1:i32, %5
%7:i1 = eq 0:i32, %6
infer %7
%8:i32 = sub %0, %1
%9:i1 = ult %8, 31:i32
result %9

This is because the RHS we want has the form (cmp hole, const); the enumerator is not handling such forms since no concrete widths are available when generating the root.

regehr commented 3 years ago

can you please add a regression test?

zhengyang92 commented 3 years ago

@regehr regression test added :)

regehr commented 3 years ago

thanks!