]> granicus.if.org Git - llvm/commit
[ConstantRange] Add overflow check helpers
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 15 Mar 2019 17:29:05 +0000 (17:29 +0000)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 15 Mar 2019 17:29:05 +0000 (17:29 +0000)
commita189aac68af392a70225102e6847a794f6a68830
treee55379ab80c782fb4a47531d6c0abfed8e7e3027
parent49abaf8b81434e54705983ca44c6704e91160e90
[ConstantRange] Add overflow check helpers

Add functions to ConstantRange that determine whether the
unsigned/signed addition/subtraction of two ConstantRanges
may/always/never overflows. This will allow checking overflow
conditions based on known constant ranges in addition to known bits.

I'm implementing these methods on ConstantRange to allow them to be
unit tested independently of any ValueTracking machinery. The tests
include exhaustive testing on 4-bit ranges, to make sure the result
is both conservatively correct and maximally precise.

The OverflowResult enum is redeclared on ConstantRange, because
I wanted to avoid a dependency in either direction between
ValueTracking.h and ConstantRange.h.

Differential Revision: https://reviews.llvm.org/D59193

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356276 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/IR/ConstantRange.h
lib/IR/ConstantRange.cpp
unittests/IR/ConstantRangeTest.cpp