clspv icon indicating copy to clipboard operation
clspv copied to clipboard

Incorrect transforms for -hack-scf

Open alan-baker opened this issue 2 years ago • 0 comments

Recently uncovered this testing abs_diff. The transformations in the pass are not safe if overflow occurs. For example signed greater than (a > b) is implemented as:

%sub = sub i32 %a, %b
%sub1 = sub i32 %sub, 1
%and = and i32 %sub1, 0x80000000
%eq = OpIEqual i32 %and, 0

Here is a problematic 8-bit case:

a = 0x7f
b = 0x8f
%sub = 0xf0
%sub1 = 0xef
%and = 0x80
%eq = false

The transform needs to handle more cases in case of potential wrapping.

alan-baker avatar Mar 17 '23 17:03 alan-baker