smack icon indicating copy to clipboard operation
smack copied to clipboard

IntegerOverflowChecker generates redundant instructions for unsigned intrinsics

Open keram88 opened this issue 7 years ago • 4 comments

Currently, instructions like @llvm.uadd.with.overflow.i32 are translated to approximately:

// %res = call {i32, i1} @llvm.uadd.with.overflow.i32(%a, %b)
...
$a1 = $zext.i32.i64($a);
$a2 = $zext.i32.i64($b);
$res = $add.i64($a1, $b1);
$over = $ugt.i64($res, UINT_MAX); // 1 if overflow
$under = $ult.i64($res, 0); // 1 if underflow
$flag = $or($over, $under); // 1 if overflow

Both arguments are unsigned, so the result will always be greater than or equal to zero, making $under redundant.

keram88 avatar Feb 01 '18 07:02 keram88

This was fixed quite some time ago. I'm not sure why it didn't get closed automatically.

keram88 avatar Jun 14 '19 18:06 keram88

Apparently it never got merged in...

keram88 avatar Oct 23 '19 01:10 keram88

@keram88 : so what is happening with this in the end? I just noticed you closed the pull request.

zvonimir avatar Oct 23 '19 15:10 zvonimir

I couldn't remember why I never made a PR for that branch, which is from June 2018. I realized that it's not quite right to completely remove the lower bound check for unsigned math since subtraction can overflow in integer mode, e.g., 2-3. I'll reopen the PR since I think I have a clean-ish way to deal with it.

keram88 avatar Oct 23 '19 15:10 keram88