This is an archive of the discontinued LLVM Phabricator instance.

remove unnecessary integer overflow checks
AbandonedPublic

Authored by regehr on Apr 14 2016, 6:18 AM.

Details

Reviewers
reames
sanjoy
Summary

This patch uses LVI to lower x.with.overflow intrinsics to the corresponding nsw instructions when an overflow provably doesn't occur. It fires about 1800 times while building LLVM with -fsanitize=signed-integer-overflow. It should fire more but it appears to be blocked by the precision of LVI's results. It looks like LVI needs a lot of fine tuning.

I consider this patch fairly low risk since it doesn't do anything unless there are integer overflow checks to look at.

I've done some testing and will continue to do more. Obviously I need to add test cases to the patch, but thought I would seek some initial feedback on the code first.

Diff Detail

Repository
rL LLVM

Event Timeline

regehr updated this revision to Diff 53695.Apr 14 2016, 6:18 AM
regehr retitled this revision from to remove unnecessary integer overflow checks.
regehr updated this object.
regehr added reviewers: sanjoy, reames.
regehr set the repository for this revision to rL LLVM.
regehr updated this revision to Diff 53945.Apr 15 2016, 1:42 PM
regehr removed rL LLVM as the repository for this revision.

Formatting fixes.

reames added inline comments.Apr 18 2016, 5:51 PM
include/llvm/Analysis/LazyValueInfo.h
74

/// Doxygen. And LLVM style.

Having this take an Instruction would make this easy to extend to proving nsw/nuw on adds.

Also, clarify what *kind* of overflow you're proving.

include/llvm/IR/ConstantRange.h
292

I don't believe you need the new API here. See makeGuaranteedNoWrapRegion

lib/Analysis/LazyValueInfo.cpp
1426

Er, Constant doesn't mean what you think it does. On integers, only the constantrange case should be triggering.

lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
359

Using OverflowingBinaryOperator might simplify this code.

390

You could make this code simpler if you wanted. You don't actually need to replace the intrinsic if you fold the overflow output to false. InstCombine will happily do that for you.

494

I'd move this inside processCallSite.

reames requested changes to this revision.Apr 18 2016, 5:52 PM
reames edited edge metadata.

p.s. We don't seem to currently infer that "a s< b" for any "b" implies that "a" is less than INT_MAX. That might be the key missing LVI change you need to make this far more effective.

This revision now requires changes to proceed.Apr 18 2016, 5:52 PM
regehr updated this revision to Diff 54176.Apr 19 2016, 5:01 AM
regehr edited edge metadata.
regehr set the repository for this revision to rL LLVM.

Added tests.

regehr abandoned this revision.May 26 2016, 1:34 AM