Commit Graph

40 Commits

Author SHA1 Message Date
Taewook Oh 960c599319 [MergeICmps] Do not perform the transformation if GEP is used outside of block
Summary:
This patch prevents MergeICmps to performn the transformation if the address operand GEP of the load instruction has a use outside of the load's parent block. Without this patch, compiler crashes with the given test case because the use of `%first.i` is still around when the basic block is erased from https://github.com/llvm-mirror/llvm/blob/master/lib/Transforms/Scalar/MergeICmps.cpp#L620. I think checking `isUsedOutsideOfBlock` with `GEP` is the original intention of the code, as the checking for `LoadI` is already performed in the same function.

This patch is incomplete though, as this makes the pass overly conservative and fails the test `tuple-four-int8.ll`. I believe what needs to be done is checking if GEP has a use outside of block that is not the part of "Comparisons" chain. Submit the patch as of now to prevent compiler crash.

Reviewers: courbet, trentxintong

Reviewed By: courbet

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346151 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-05 18:16:32 +00:00
Christy Lee d87fb985a5 Pointer types were treated as zero-size by MergeICmps
Summary:
The visitICmp analysis function would record compares of pointer types, as size 0. This causes the resulting memcmp() call to have the wrong total size.
Found with "self-build" of clang/LLVM on Windows.

Reviewers: christylee, trentxintong, courbet

Reviewed By: courbet

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345413 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-26 18:02:06 +00:00
Fangrui Song 3b35e17b21 llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)
Summary: The convenience wrapper in STLExtras is available since rL342102.

Reviewers: dblaikie, javed.absar, JDevlieghere, andreadb

Subscribers: MatzeB, sanjoy, arsenm, dschuff, mehdi_amini, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, eraman, aheejin, kbarton, JDevlieghere, javed.absar, gbedwell, jrtc27, mgrang, atanasyan, steven_wu, george.burgess.iv, dexonsmith, kristina, jsji, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343163 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-27 02:13:45 +00:00
Christy Lee 2d8135ffd9 Re-submitting changes in D51550 because it failed to patch.
Reviewers: javed.absar, trentxintong, courbet

Reviewed By: trentxintong

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342919 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-24 20:47:12 +00:00
Christy Lee fbb826fa5c Do not optimize atomic load to non-atomic memcmp
Differential Revision: https://reviews.llvm.org/D51998

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342498 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-18 17:02:42 +00:00
Benjamin Kramer 9174d3e272 [MergeICmps] Don't crash when memcmp is not available
Fixes clang crashing with -fno-builtin, PR37527.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332808 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-19 12:51:59 +00:00
Nicola Zaghen 0818e789cb Rename DEBUG macro to LLVM_DEBUG.
The DEBUG() macro is very generic so it might clash with other projects.
The renaming was done as follows:
- git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g'
- git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM
- Manual change to APInt
- Manually chage DOCS as regex doesn't match it.

In the transition period the DEBUG() macro is still present and aliased
to the LLVM_DEBUG() one.

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332240 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-14 12:53:11 +00:00
Hiroshi Inoue c4c17fac46 [NFC] fix trivial typos in document and comments
"not not" -> "not" etc



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330083 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-14 08:59:00 +00:00
Mandeep Singh Grang 15ff8cad10 [Transforms] Change std::sort to llvm::sort in response to r327219
Summary:
r327219 added wrappers to std::sort which randomly shuffle the container before sorting.
This will help in uncovering non-determinism caused due to undefined sorting
order of objects having the same key.

To make use of that infrastructure we need to invoke llvm::sort instead of std::sort.

Note: This patch is one of a series of patches to replace *all* std::sort to llvm::sort.
Refer the comments section in D44363 for a list of all the required patches.

Reviewers: kcc, pcc, danielcdh, jmolloy, sanjoy, dberlin, ruiu

Reviewed By: ruiu

Subscribers: ruiu, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330059 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-13 19:47:57 +00:00
Xin Tong 3c11d1113d [MergeICmp] Update debug msg.NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329572 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-09 14:29:13 +00:00
Xin Tong efcfc6694b [MergeICmp] Split blocks that do other work.
Summary:
We do not try to move the instructions and split the block till we
know the blocks can be split, i.e. BCE-cmp-insts can be separated from
non-BCE-cmp-insts.

Reviewers: davide, courbet

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329564 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-09 13:14:06 +00:00
Xin Tong 10b8d1571c 80-line wrap. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328660 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-27 19:43:02 +00:00
Xin Tong 8e6d19ebe4 [MergeICmps] Break eargerly out of loop
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327972 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-20 12:03:25 +00:00
Xin Tong d89cc9594c [MergeICmp] Fix a bug in entry block shuffled to middle of the chain
Summary: Fix a bug in entry block shuffled to middle of the chain.

Reviewers: davide, courbet

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327971 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-20 11:57:54 +00:00
Clement Courbet cfe9a0e905 [MergeICmps] Make sure that the comparison only has one use.
Summary: Fixes PR36557.

Reviewers: trentxintong, spatel

Subscribers: mstorsjo, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327372 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-13 07:05:55 +00:00
Xin Tong 434547e0c5 [MergeICmp] Simplify how BCECmpBlock instructions are blacklisted
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326761 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-06 02:24:02 +00:00
Xin Tong 806f65e3f5 [MergeICmp] Fix printing. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326760 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-06 02:04:57 +00:00
Xin Tong ec1d1788ce [MergeICmp] We can discard initial blocks that do other work
Summary:
 We can discard initial blocks that do other work
We do not need to limit ourselves to just the first block in the chain.

Reviewers: courbet, davide

Reviewed By: courbet

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326698 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-05 13:54:47 +00:00
Clement Courbet a6e171db6c [MergeICmps][NFC] Improve logging.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326683 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-05 08:21:47 +00:00
Xin Tong ed2b4e5df9 Fix typo. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326319 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-28 12:09:53 +00:00
Xin Tong 5de243758f [MergeICmp] Fix a bug in MergeICmp that can lead to a block being processed more than once.
Summary:
Fix a bug in MergeICmp that can lead to a BCECmp block being processed more than once and eventually lead to a broken LLVM module.
The problem is that if the non-constant value is not produced by the last block, the producer will be processed once when the its parent block
is processed and second time when the last block is processed.

We end up having 2 same BCECmpBlock in the merge queue. And eventually lead to a broken LLVM module.

Reviewers: courbet, davide

Reviewed By: courbet

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326318 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-28 12:08:00 +00:00
Clement Courbet bed04b64f4 [MergeICmps] Handle chains with several complex BCE basic blocks.
- Fix condition for detecting that a complex basic block was the first in
   the chain.
 - Add tests.

This was caught by buildbots when submitting rL324319.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@324341 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-06 12:25:33 +00:00
Clement Courbet ee84001a30 [MergeICmps][NFC] Add more assertions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@324323 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-06 09:14:00 +00:00
Hiroshi Inoue 1cc0555256 [NFC] fix trivial typos in comments
"the the" -> "the"



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@322934 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-19 10:55:29 +00:00
Michael Zolotukhin d5c7271167 Remove redundant includes from lib/Transforms.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320628 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-13 21:31:01 +00:00
Clement Courbet 4ccf677f27 [CodeGen][ExpandMemcmp] Allow memcmp to expand to vector loads (2).
- Targets that want to support memcmp expansions now return the list of
   supported load sizes.
 - Expansion codegen does not assume that all power-of-two load sizes
   smaller than the max load size are valid. For examples, this is not the
   case for x86(32bit)+sse2.

Fixes PR34887.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316905 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-30 14:19:33 +00:00
Eugene Zelenko 0dfe884a45 [Transforms] Revert r316630 changes in Scalar/MergeICmps.cpp to fix broken build bots (NFC).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316634 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-26 01:25:14 +00:00
Eugene Zelenko 46057fe01a [Transforms] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316630 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-26 00:55:39 +00:00
Clement Courbet cdaf07d82e Re-land "[MergeICmps] Disable mergeicmps if the target does not want to handle memcmp expansion."
(fixed stability issues)

This reverts commit d6492333d3b478a1d88163315002022f8d5e58dc.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315281 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-10 08:00:45 +00:00
Clement Courbet d51f64169e Revert "[MergeICmps] Disable mergeicmps if the target does not want to handle memcmp expansion."
Still a few stability issues on windows.

This reverts commit 67e3db9bc121ba244e20337aabc7cf341a62b545.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315058 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-06 13:02:24 +00:00
Clement Courbet 13426d53c5 Re-land "[MergeICmps] Disable mergeicmps if the target does not want to handle memcmp expansion."
(fixed unit tests by making comparisons stable)

This reverts commit 1b2d359ce256fd6737da4e93833346a0bd6d7583.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315056 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-06 12:12:35 +00:00
Clement Courbet a9a80eaeee Revert "Re-land "[MergeICmps] Disable mergeicmps if the target does not want to handle memcmp expansion."""
broken test on windows

This reverts commit c91479518344fd1fc071c5bd5848f6eb83e53dca.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314985 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-05 14:42:06 +00:00
Clement Courbet f7ceddc7e6 Re-land "[MergeICmps] Disable mergeicmps if the target does not want to handle memcmp expansion.""
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314980 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-05 12:39:57 +00:00
Clement Courbet bdbb17febd Revert "[MergeICmps] Disable mergeicmps if the target does not want to handle memcmp expansion."
Breaks
clang-stage1-cmake-RA-incremental/llvm/test/Transforms/MergeICmps/X86/tuple-four-int8.ll

This reverts commit 3038c459d67f8898ffa295d54a013b280690abfa.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314972 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-05 08:03:39 +00:00
Clement Courbet 17f5bd1520 [MergeICmps] Disable mergeicmps if the target does not want to handle memcmp expansion.
Summary: This is to avoid e.g. merging two cheap icmps if the target is not going to expand to something nice later.

Reviewers: dberlin, spatel

Subscribers: davide, nemanjai

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314970 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-05 07:49:09 +00:00
Clement Courbet c0d3fd047b [NFC] clang-format lib/Transforms/Scalar/MergeICmps.cpp
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314906 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-04 15:13:52 +00:00
Clement Courbet 50c7531ed4 [MergeICmps] Fix build of rL312315 on clang-with-thin-lto-windows:
MergeICmps.cpp(68,15): error: chosen constructor is explicit in copy-initialization
      return {};
APInt.h(339,12): note: explicit constructor declared here
  explicit APInt() : BitWidth(1) { U.VAL = 0; }
             ^
MergeICmps.cpp(56,9): note: in implicit initialization of field 'Offset' with omitted
initializer
  APInt Offset;
          ^

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312326 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-01 11:51:23 +00:00
Clement Courbet 4855d2de9a Reland rL312315: [MergeICmps] MergeICmps is a new optimization pass that turns chains of integer
Add missing header.

This reverts commit 86dd6335cf7607af22f383a9a8e072ba929848cf.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312322 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-01 10:56:34 +00:00
Clement Courbet 1a4fd5c74c Revert "[MergeICmps] MergeICmps is a new optimization pass that turns chains of integer"
Break build

This reverts commit d07ab866f7f88f81e49046d691a80dcd32d7198b.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312317 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-01 09:43:08 +00:00
Clement Courbet 930b028c65 [MergeICmps] MergeICmps is a new optimization pass that turns chains of integer
comparisons into memcmp.

Thanks to recent improvements in the LLVM codegen, the memcmp is typically
inlined as a chain of efficient hardware comparisons.
This typically benefits C++ member or nonmember operator==().

For now this is disabled by default until:
 - https://bugs.llvm.org/show_bug.cgi?id=33329 is complete
 - Benchmarks show that this is always useful.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312315 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-01 09:07:05 +00:00