16505 Commits

Author SHA1 Message Date
Sanjay Patel
a8a96a9e94 [InstCombine] use dyn_cast rather isa+cast; NFC
Follow-up to r286664 cleanup as suggested by Eli. Thanks!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286671 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 23:20:01 +00:00
Sanjay Patel
9728332add [InstCombine] clean up foldSelectOpOp(); NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286664 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 23:01:20 +00:00
Anna Zaks
1a26404f05 [tsan][llvm] Implement the function attribute to disable TSan checking at run time
This implements a function annotation that disables TSan checking for the
function at run time. The benefit over attribute((no_sanitize("thread")))
is that the accesses within the callees will also be suppressed.

The motivation for this attribute is a guarantee given by the objective C
language that the calls to the reference count decrement and object
deallocation will be synchronized. To model this properly, we would need
to intercept all ref count decrement calls (which are very common in ObjC
due to use of ARC) and also every single message send. Instead, we propose
to just ignore all accesses made from within dealloc at run time. The main
downside is that this still does not introduce any synchronization, which
means we might still report false positives if the code that relies on this
synchronization is not executed from within dealloc. However, we have not seen
this in practice so far and think these cases will be very rare.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286663 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 23:01:02 +00:00
Adam Nemet
7f0fc37d0d [LV] Stop saying "use -Rpass-analysis=loop-vectorize"
This is PR28376.

Unfortunately given the current structure of optimization diagnostics we
lack the capability to tell whether the user has
passed -Rpass-analysis=loop-vectorize since this is local to the
front-end (BackendConsumer::OptimizationRemarkHandler).

So rather than printing this even if the user has already
passed -Rpass-analysis, this patch just punts and stops recommending
this option.  I don't think that getting this right is worth the
complexity.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286662 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 22:51:46 +00:00
Erik Eckstein
eec5bf79c3 FunctionComparator: don't rely on argument evaluation order.
This is a follow-up on the recent refactoring of the FunctionMerge pass.
It should fix a fail of the new FunctionComparator unittest whe compiling with MSVC.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286648 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 22:21:39 +00:00
Evgeniy Stepanov
06f9b86145 [cfi] Fix weak functions handling.
When a function pointer is replaced with a jumptable pointer, special
case is needed to preserve the semantics of extern_weak functions.
Since a jumptable entry can not be extern_weak, we emulate that
behaviour by replacing all references to F (the extern_weak function)
with the following expression: F != nullptr ? JumpTablePtr : nullptr.

Extra special care is needed for global initializers, since most (or
probably all) backends can not lower an initializer that includes
this kind of constant expression. Initializers like that are replaced
with a global constructor (i.e. a runtime initializer).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286636 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 21:39:26 +00:00
Erik Eckstein
345d21cba1 Make the FunctionComparator of the MergeFunctions pass a stand-alone utility.
This is pure refactoring. NFC.

This change moves the FunctionComparator (together with the GlobalNumberState
utility) in to a separate file so that it can be used by other passes.
For example, the SwiftMergeFunctions pass in the Swift compiler:
https://github.com/apple/swift/blob/master/lib/LLVMPasses/LLVMMergeFunctions.cpp

Details of the change:

*) The big part is just moving code out of MergeFunctions.cpp into FunctionComparator.h/cpp
*) Make FunctionComparator member functions protected (instead of private)
   so that a derived comparator class can use them.

Following refactoring helps to share code between the base FunctionComparator
class and a derived class:

*) Add a beginCompare() function
*) Move some basic function property comparisons into a separate function compareSignature()
*) Do the GEP comparison inside cmpOperations() which now has a new
   needToCmpOperands reference parameter

https://reviews.llvm.org/D25385



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286632 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 21:15:13 +00:00
Vyacheslav Klochkov
35cecc31aa Fixed the lost FastMathFlags for FCmp operations in SLPVectorizer.
Reviewer: Michael Zolotukhin.
Differential Revision: https://reviews.llvm.org/D26543


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286626 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 19:55:29 +00:00
Peter Collingbourne
aeb2eff8d2 Bitcode: Change getModuleSummaryIndex() to return an llvm::Expected.
Differential Revision: https://reviews.llvm.org/D26539

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286624 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 19:50:39 +00:00
Reid Kleckner
d758cd3129 [sancov] Don't instrument MSVC CRT stdio config helpers
They get called before initialization, which is a problem for winasan.

Test coming in compiler-rt.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286615 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 19:18:45 +00:00
Evgeniy Stepanov
81323af362 [cfi] Implement cfi-icall using inline assembly.
The current implementation is emitting a global constant that happens
to evaluate to the same bytes + relocation as a jump instruction on
X86. This does not work for PIE executables and shared libraries
though, because we end up with a wrong relocation type. And it has no
chance of working on ARM/AArch64 which use different relocation types
for jump instructions (R_ARM_JUMP24) that is never generated for
data.

This change replaces the constant with module-level inline assembly
followed by a hidden declaration of the jump table. Works fine for
ARM/AArch64, but has some drawbacks.
* Extra symbols are added to the static symbol table, which inflate
the size of the unstripped binary a little. Stripped binaries are not
affected. This happens because jump table declarations must be
external (because their body is in the inline asm).
* Original functions that were anonymous are now named
<original name>.cfi, and it affects symbolization sometimes. This is
necessary because the only user of these functions is the (inline
asm) jump table, so they had to be added to @llvm.used, which does
not allow unnamed functions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286611 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 18:49:09 +00:00
Sanjay Patel
d78e6da29d [InstCombine] fix formatting of FoldOpIntoSelect(); NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286604 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 17:42:16 +00:00
Dehao Chen
fb6e3a842a Add comments about why we put LoopSink pass at the very late stage.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286480 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-10 17:42:18 +00:00
Sanjay Patel
9c5e4bac4a [InstCombine] avoid infinite loop from shuffle-extract-insert sequence (PR30923)
Removing the limitation in visitInsertElementInst() causes several regressions
because we're not prepared to fold sequences of shuffles or inserts and extracts
separated by shuffles. Fixing that appears to be a difficult mission because we
are purposely trying to avoid creating shuffles with arbitrary shuffle masks
because some targets may choke on those.

https://llvm.org/bugs/show_bug.cgi?id=30923


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286423 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-10 00:15:14 +00:00
Eli Friedman
0e23db6f4e Preserve assumption cache in loop-rotate.
No testcase included because I can't figure out how to reduce it.
(It's easy to write a testcase where rotation clones an assume,
but that doesn't actually seem to trigger the crash in opt on
its own; maybe an issue with the laziness?)

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286410 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-09 23:05:01 +00:00
Evgeny Stupachenko
faf81d7b4b Minor unroll pass refacoring.
Summary:
Unrolled Loop Size calculations moved to a function.
Constant representing number of optimized instructions
 when "back edge" becomes "fall through" replaced with
 variable.
Some comments added.

Reviewers: mzolotukhin

Differential Revision: http://reviews.llvm.org/D21719

From: Evgeny Stupachenko <evstupac@gmail.com>


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286389 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-09 19:56:39 +00:00
Peter Collingbourne
76c218e094 Bitcode: Change the materializer interface to return llvm::Error.
Differential Revision: https://reviews.llvm.org/D26439

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286382 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-09 17:49:19 +00:00
Pavel Labath
15f3ab0cb6 Remove TimeValue usage from Scalar/SROA.cpp. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286361 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-09 12:07:12 +00:00
Alexandros Lamprineas
32054b584b [ARM] Loop Strength Reduction crashes when targeting ARM or Thumb.
Scalar Evolution asserts when not all the operands of an Add Recurrence
Expression are loop invariants. Loop Strength Reduction should only
create affine Add Recurrences, so that both the start and the step of
the expression are loop invariants.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286347 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-09 08:53:07 +00:00
Dehao Chen
3885b5c478 Enable Loop Sink pass for functions that has profile.
Summary: For functions with profile data, we are confident that loop sink will be optimal in sinking code.

Reviewers: davidxl, hfinkel

Subscribers: mehdi_amini, mzolotukhin, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286325 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-09 00:58:19 +00:00
Sanjay Patel
6382ee0e42 [InstCombine] fix profitability equation for max-of-nots transform
As the test change shows, we can increase the critical path by adding
a 'not' instruction, so make sure that we're actually removing an
instruction if we do this transform.

This transform could also cause us to miss folds of min/max pairs.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286315 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-09 00:13:11 +00:00
Sanjay Patel
97d780bf60 [InstCombine] reduce indentation; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286314 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-08 23:49:15 +00:00
Kuba Brecka
4f349ace2b [asan] Speed up compilation of large C++ stringmaps (tons of allocas) with ASan
This addresses PR30746, <https://llvm.org/bugs/show_bug.cgi?id=30746>. The ASan pass iterates over entry-block instructions and checks each alloca whether it's in NonInstrumentedStaticAllocaVec, which is apparently slow. This patch gathers the instructions to move during visitAllocaInst.

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286296 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-08 21:30:41 +00:00
Davide Italiano
18fd3e63e3 [LoopDistribute] Preserve GlobalsAA also in the new Pass Manager.
Differential Revision:  https://reviews.llvm.org/D26408

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286280 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-08 19:52:32 +00:00
Davide Italiano
9579593784 [LibcallsShrinkWrap] This pass doesn't preserve the CFG.
For example, it invalidates the domtree, causing assertions
in later passes which need dominator infos. Make it preserve
GlobalsAA, as suggested by Eli.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286271 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-08 19:18:20 +00:00
Chad Rosier
e481b32815 Fix typo in comment. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286270 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-08 19:10:25 +00:00
Chad Rosier
5addea50b7 Remove unused include. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286250 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-08 16:51:19 +00:00
Dehao Chen
43252d0179 Use the last 7 bits to represent the discriminator to fit it in 1 byte ULEB128 (NFC).
From experiments, discriminator is rarely greater than 127. Here we enforce it to be no greater than 127 so that it will always fit in 1 byte.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286245 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-08 16:32:32 +00:00
Pablo Barrio
ac54d0066c [JumpThreading] Unfold selects that depend on the same condition
Summary:
These are good candidates for jump threading. This enables later opts
(such as InstCombine) to combine instructions from the selects with
instructions out of the selects. SimplifyCFG will fold the select
again if unfolding wasn't worth it.

Patch by James Molloy and Pablo Barrio.

Reviewers: rengolin, haicheng, sebpop

Subscribers: jojo, jmolloy, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286236 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-08 14:53:30 +00:00
Sanjoy Das
3e9cd162c0 [TRE] Remove dead code
Address review by Eli Friedman on rL286147.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286165 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-07 22:17:37 +00:00
Dehao Chen
cc1ad89bbb Reset debug loc to OldInduction in InnerLoopVectorizer::createInductionVariable. (NFC)
This is to prevent SetInsertionPoint from setting debug loc to Latch->getTerminator().


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286159 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-07 21:59:40 +00:00
Sanjoy Das
daf21289b6 Avoid tail recursion elimination across calls with operand bundles
Summary:
In some specific scenarios with well understood operand bundle types
(like `"deopt"`) it may be possible to go ahead and convert recursion to
iteration, but TailRecursionElimination does not have that logic today
so avoid doing the right thing for now.

I need some input on whether `"funclet"` operand bundles should also
block tail recursion elimination.  If not, I'll allow TRE across calls
with `"funclet"` operand bundles and add a test case.

Reviewers: rnk, majnemer, nlewycky, ahatanak

Subscribers: mcrosier, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286147 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-07 21:01:49 +00:00
Evgeniy Stepanov
d2b47f0e27 Use -fsanitize-recover instead of -mllvm -msan-keep-going.
Summary: Use -fsanitize-recover instead of -mllvm -msan-keep-going.

Reviewers: eugenis

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286145 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-07 21:00:10 +00:00
Kuba Brecka
8882bb7633 [tsan] Cast floating-point types correctly when instrumenting atomic accesses, LLVM part
Although rare, atomic accesses to floating-point types seem to be valid, i.e. `%a = load atomic float ...`. The TSan instrumentation pass however tries to emit inttoptr, which is incorrect, we should use a bitcast here. Anyway, IRBuilder already has a convenient helper function for this.

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286135 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-07 19:09:56 +00:00
Benjamin Kramer
cfce1b9424 [MemCpyOpt] Don't emit IR in an unspecified order
Argument evaluation order is one of the edge cases where Clang differs
from GCC, yielding different IR depending on which compiler LLVM was
built with. Make the order deterministic and tune the test to actually
verify the order instead of trying to hide it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286126 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-07 17:47:28 +00:00
Chad Rosier
e670c88387 Fix 80-column violations. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286117 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-07 16:28:04 +00:00
Sanjay Patel
901ccced28 [InstCombine] allow splat vector folds in adjustMinMax() (retry r285732)
This was reverted at r285866 because there was a crash handling a scalar
select of vectors. I added a check for that pattern and a test case based
on the example provided in the post-commit thread for r285732.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286113 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-07 15:52:45 +00:00
Justin Lebar
de1867fd43 [LoopStrengthReduce] Don't use a DenseSet<int64_t> when we might add any valid int64_t to the set.
Summary:
SmallSetVector uses DenseSet, but that means we need to reserve some
values for the empty and tombstone keys.

It seems to me we should have a general way to let us store full-range
ints inside of DenseSets, and furthermore that we probably shouldn't
silently let you add ints into DenseSets without explicitly promising
that they're in range.  But that's a battle for another day; for now,
just fix this code, since we currently do something Very Bad when
compiling ffmpeg.

Fixes PR30914.

Reviewers: jeremyhu

Subscribers: llvm-commits, mzolotukhin

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286038 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-05 16:47:25 +00:00
Chandler Carruth
6c10c8c944 Only log the visit of a return instruction if we in fact found a return
instruction.

This avoids dereferencing null in the debug logging if the instruction
was not in fact a return instruction. This potential bug was found by
PVS-Studio.

This actually fixes the last of the "dereferenced a pointer before
checking it for null" reports in the recent PVS-Studio run. However,
there are quite a few reports of this nature that I did not do anything
to fix because they are pretty glaring false positives. They usually
took the form of quite clear correlated checks or a check made in
a separate function. I've even added asserts anywhere this correlation
wasn't pretty obvious and fundamental to the code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285988 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-04 06:59:50 +00:00
Xinliang David Li
af0210fd51 Fix typo
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285978 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-04 03:00:52 +00:00
Chandler Carruth
b2400000cc Fix a bug found by inspection by PVS-Studio.
This condition is trivially always true prior to the change. The comment
at the call site makes it clear that we expect *all* of these to be '=',
'S', or 'I' so fix the code.

We have a bug I will update to track the fact that Clang doesn't warn on
this: http://llvm.org/PR13101

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285930 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-03 16:39:25 +00:00
Teresa Johnson
6e15e36dae [ThinLTO] Handle distributed backend case when doing renaming
Summary:
The recent change I made to consult the summary when deciding whether to
rename (to handle inline asm) in r285513 broke the distributed build
case. In a distributed backend we will only have a portion of the
combined index, specifically for imported modules we only have the
summaries for any imported definitions. When renaming on import we were
asserting because no summary entry was found for a local reference being
linked in (def wasn't imported).

We only need to consult the summary for a renaming decision for the
exporting module. For imports, we would have prevented importing any
references to NoRename values already.

Reviewers: mehdi_amini

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285871 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-03 01:07:16 +00:00
Greg Bedwell
2ad749ea5e Revert "[InstCombine] allow splat vector folds in adjustMinMax()"
This reverts commit r285732.

This change introduced a new assertion failure in the following
testcase at -O2:

typedef short __v8hi __attribute__((__vector_size__(16)));
__v8hi foo(__v8hi &V1, __v8hi &V2, unsigned mask) {
  __v8hi Result = V1;
  if (mask & 0x80)
    Result[0] = V2[0];
  return Result;
}

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285866 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-02 23:17:05 +00:00
Eli Friedman
a7bfb15b26 DCE math library calls with a constant operand.
On platforms which use -fmath-errno, math libcalls without any uses
require some extra checks to figure out if they are actually dead.

Fixes https://llvm.org/bugs/show_bug.cgi?id=30464 .

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285857 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-02 20:48:11 +00:00
Bjorn Pettersson
4513397601 [Reassociate] Skip analysis of dead code to avoid infinite loop.
Summary:
It was detected that the reassociate pass could enter an inifite
loop when analysing dead code. Simply skipping to analyse basic
blocks that are dead avoids such problems (and as a side effect
we avoid spending time on optimising dead code).

The solution is using the same Reverse Post Order ordering of the
basic blocks when doing the optimisations, as when building the
precalculated rank map. A nice side-effect of this solution is
that we now know that we only try to do optimisations for blocks
with ranked instructions.

Fixes https://llvm.org/bugs/show_bug.cgi?id=30818

Reviewers: llvm-commits, davide, eli.friedman, mehdi_amini

Subscribers: dberlin

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285793 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-02 08:55:19 +00:00
George Burgess IV
fc92168d01 [MemorySSA] Tighten up types to make our API prettier. NFC.
Patch by bryant.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285750 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-01 21:17:46 +00:00
Sanjay Patel
b40f34e4b3 [InstCombine] allow splat vector folds in adjustMinMax()
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285732 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-01 20:08:02 +00:00
Sanjay Patel
e7291efa87 [InstCombine] Fold nuw left-shifts in ugt/ule comparisons.
This transforms

%a = shl nuw %x, c1
%b = icmp {ugt|ule} %a, c0

into

%b = icmp {ugt|ule} %x, (c0 >> c1)

z3:

(declare-const x (_ BitVec 64))
(declare-const c0 (_ BitVec 64))
(declare-const c1 (_ BitVec 64))

(push)
(assert (= x (bvlshr (bvshl x c1) c1)))  ; nuw
(assert (not (= (bvugt (bvshl x c1) c0)
                (bvugt x
                       (bvlshr c0 c1)))))
(check-sat)
(get-model)
(pop)

(push)
(assert (= x (bvlshr (bvshl x c1) c1)))  ; nuw
(assert (not (= (bvule (bvshl x c1) c0)
                (bvule x
                       (bvlshr c0 c1)))))
(check-sat)
(get-model)
(pop)

Patch by bryant!

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285729 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-01 19:19:29 +00:00
Sanjay Patel
cb06b587a2 [InstCombine] clean up adjustMinMax(); NFCI
1. Change param names for readability
2. Change pointer param to ref
3. Early exit to reduce indent
4. Change switch to if/else


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285718 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-01 18:15:03 +00:00
Sanjay Patel
f89a6d6792 [InstCombine] add helper function for adjustMinMax(); NFCI
This is just a cut and paste; clean-up and enhancements to follow.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285715 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-01 17:46:08 +00:00