144341 Commits

Author SHA1 Message Date
Matt Arsenault
982ff7f443 AMDGPU: Improve nsw/nuw/exact when promoting uniform i16 ops
These were simply preserving the flags of the original operation,
which was too conservative in most cases and incorrect for mul.

nsw/nuw may be needed for some combines to cleanup messes when
intermediate sext_inregs are introduced later.

Tested valid combinations with alive.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293776 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 16:25:23 +00:00
Sanjoy Das
2e079eaf6b [ImplicitNullCheck] Extend canReorder scope
Summary:
This change allows a re-order of two intructions if their uses
are overlapped.

Patch by Serguei Katkov!

Reviewers: reames, sanjoy

Reviewed By: sanjoy

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293775 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 16:04:21 +00:00
Sanjay Patel
ab1df8f850 [ValueTracking] avoid crashing from bad assumptions (PR31809)
A program may contain llvm.assume info that disagrees with other analysis. 
This may be caused by UB in the program, so we must not crash because of that.

As noted in the code comments:
https://llvm.org/bugs/show_bug.cgi?id=31809
...we can do better, but this at least avoids the assert/crash in the bug report.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293773 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 15:41:32 +00:00
Simon Dardis
537adc9cac [mips] Fix an initialization issue with MipsABIInfo in MipsTargetELFStreamer
DebugInfoDWARFTests is the only user so far which initializes the
MCObjectStreamer without initializing the ASMParser. The MIPS backend
relies on the ASMParser to initialize the MipsABIInfo object and to
update the target streamer with it. This should turn the mips buildbots
green.

Reviewers: atanasyan, zoran.jovanovic

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293772 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 15:39:23 +00:00
Kit Barton
447c100995 [PowerPC] Fix sjlj pseduo instructions to use G8RC_NOX0 register class
The the following instructions:
  - LD/LWZ (expanded from sjLj pseudo-instructions)
  - LXVL/LXVLL vector loads
  - STXVL/STXVLL vector stores
all require G8RC_NO0X class registers for RA.

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

Committed for Lei Huang

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293769 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 14:33:57 +00:00
Simon Pilgrim
30afc90a60 [X86][SSE] Merge SSE2 PINSRW lowering with SSE41 PINSRB/PINSRW lowering. NFCI.
These are identical apart from the extra SSE41 guard for PINSRB.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293766 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 13:32:19 +00:00
Florian Hahn
47d1df4cfd [legalizetypes] Push fp16 -> fp32 extension node to worklist.
Summary:
This way, the type legalization machinery will take care of registering
the result of this node properly.

This patches fixes all failing fp16 test cases  with expensive checks.
(CodeGen/ARM/fp16-promote.ll, CodeGen/ARM/fp16.ll, CodeGen/X86/cvt16.ll
CodeGen/X86/soft-fp.ll) 


Reviewers: t.p.northover, baldrick, olista01, bogner, jmolloy, davidxl, ab, echristo, hfinkel

Reviewed By: hfinkel

Subscribers: mehdi_amini, hfinkel, davide, RKSimon, aemerson, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293765 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 13:01:33 +00:00
Sam Parker
1cc548752f [ARM] const cast fix for ARMAttributeParser test
GCC 4.8 produced a cast qualifier warning, so replaced with C++ style
const cast.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293764 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 12:58:57 +00:00
Artur Pilipenko
38847f25fe [LoopPredication] Add a new line to debug output in LoopPredication pass
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293762 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 12:25:38 +00:00
Javed Absar
bddaeb4ffb [ARM] Enable Cortex-M23 and Cortex-M33 support.
Add both cores to the target parser and TableGen. Test that eabi
attributes are set correctly for both cores. Additionally, test the
absence and presence of MOVT in Cortex-M23 and Cortex-M33, respectively.

Committed on behalf of Sanne Wouda.
Reviewers : rengolin, olista01.

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293761 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 11:55:03 +00:00
Daniel Sanders
40a8ce7678 [globalisel] Make the MatchAction hierarchy consistent with the matchers. NFC.
Reviewers: aditya_nandakumar, rovka, t.p.northover, qcolombet, ab

Subscribers: dberris, llvm-commits, kristof.beyls

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293760 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 10:53:10 +00:00
Florian Hahn
7b41d2df25 [LoopUnroll] Use addClonedBlockToLoopInfo to add loop header to LI (NFC).
Summary:
I have a similar patch up for review already (D29173). If you prefer I
can squash them both together.

Also I think there more potential for code sharing between
LoopUnroll.cpp and LoopUnrollRuntime.cpp. Do you think patches for
that would be worthwhile? 

Reviewers: mkuper, mzolotukhin

Reviewed By: mkuper, mzolotukhin

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293758 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 10:39:35 +00:00
NAKAMURA Takumi
e11ce9f853 *MacroFusion.cpp: Suppress warnings to eliminate \param(s). [-Wdocumentation]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293744 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 07:30:46 +00:00
Craig Topper
7270af403d [X86] For AVX1/AVX2 isel, don't use FP move instructions for 128-bit loads/stores of integer types.
For SSE we use fp because of the smaller encoding, but that doesn't apply to AVX. So just do the natural thing so we don't have to explain why we aren't. We can't do this for 256-bit loads/stores since integer loads and stores aren't available in AVX1 so we need fallback patterns since the integer types are legal.

This doesn't affect any tests because execution domain fixing freely converts the instructions anyway. Honestly, we could probably rely on it for the SSE size optimization too.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293743 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 07:17:16 +00:00
Evandro Menezes
7fba976622 [AArch64] Add new target feature to fuse literal generation
This feature enables the fusion of such operations on Cortex A57, as
recommended in its Software Optimisation Guide, sections 4.14 and 4.15.

Differential revision: https://reviews.llvm.org/D28698

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293739 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 02:54:42 +00:00
Evandro Menezes
fa7db79431 [AArch64] Add new subtarget feature to fuse AES crypto operations
This feature enables the fusion of such operations on Cortex A57, as
recommended in its Software Optimisation Guide, section 4.13, and on Exynos
M1.

Differential revision: https://reviews.llvm.org/D28491

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293738 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 02:54:39 +00:00
Evandro Menezes
20de1ea345 [CodeGen] Move MacroFusion to the target
This patch moves the class for scheduling adjacent instructions,
MacroFusion, to the target.

In AArch64, it also expands the fusion to all instructions pairs in a
scheduling block, beyond just among the predecessors of the branch at the
end.

Differential revision: https://reviews.llvm.org/D28489

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293737 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 02:54:34 +00:00
Sanjoy Das
dfddad6ef0 [ImplicitNullCheck] NFC isSuitableMemoryOp cleanup
Summary:
isSuitableMemoryOp method is repsonsible for verification
that instruction is a candidate to use in implicit null check.
Additionally it checks that base register is not re-defined before.
In case base has been re-defined it just returns false and lookup
is continued while any suitable instruction will not succeed this check
as well. This results in redundant further operations.

So when we found that base register has been re-defined we just
stop.

Patch by Serguei Katkov!

Reviewers: reames, sanjoy

Reviewed By: sanjoy

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293736 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 02:49:25 +00:00
Justin Bogner
770cb8b1b5 SanitizerCoverage: Support sanitizer guard section on darwin
MachO's sections need a segment as well as a section name, and the
section start and end symbols are spelled differently than on ELF.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293733 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 02:38:39 +00:00
Matthias Braun
c7e7654a88 MCMacho: Allow __thread_ptr section after dwarf sections
Differential Revision: https://reviews.llvm.org/D29315

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293730 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 01:31:36 +00:00
Eugene Zelenko
c7e2e47b27 [Mips] 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@293729 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 01:22:51 +00:00
Stanislav Mekhanoshin
036be2d186 Fix regalloc assignment of overlapping registers
SplitEditor::defFromParent() can create a register copy.
If register is a tuple of other registers and not all lanes are used
a copy will be done on a full tuple regardless. Later register unit
for an unused lane will be considered free and another overlapping
register tuple can be assigned to a different value even though first
register is live at that point. That is because interference only look at
liveness info, while full register copy clobbers all lanes, even unused.

This patch fixes copy to only cover used lanes.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293728 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 01:18:36 +00:00
Davide Italiano
fb36e6d33b [IPSCCP] Teach how to not propagate return values of naked functions.
Differential Revision:  https://reviews.llvm.org/D29360

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293727 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 01:01:22 +00:00
Matt Arsenault
2415a7067f AMDGPU: Cleanup fmin/fmax legacy function
Use a more specific subtarget check and combine hasOneUse checks

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293726 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 00:42:40 +00:00
Dean Michael Berris
dd336006bd [XRay] Use std::errc::invalid_argument instead of std::errc::bad_message
This change should appease the mingw32 builds.

Follow-up to D29319.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293725 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 00:22:20 +00:00
Matt Arsenault
40fe3a93e9 InferAddressSpaces: Handle select
This fails to handle some cases where one of the inputs is
a constant to be fixed in a later commit.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293723 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 00:08:53 +00:00
Kostya Serebryany
63c362484c [libFuzzer] increase the default size for shmem
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293722 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 00:07:47 +00:00
Dean Michael Berris
93789c8851 [XRay] Define the InstrumentationMap type
Summary:
This change implements the instrumentation map loading library which can
understand both YAML-defined instrumentation maps, and ELF 64-bit object
files that have the XRay instrumentation map section. We break it out
into a library on its own to allow for other applications to deal with
the XRay instrumentation map defined in XRay-instrumented binaries.

This type provides both raw access to the logical representation of the
instrumentation map entries as well as higher level functions for
converting a function ID into a function address.

At this point we only support ELF64 binaries and YAML-defined XRay
instrumentation maps. Future changes should extend this to support
32-bit ELF binaries, as well as other binary formats (like MachO).

As part of this change we also migrate all uses of the extraction logic
that used to be defined in tools/llvm-xray/ to use this new type and
interface for loading from files. We also remove the flag from the
`llvm-xray` tool that required users to specify the type of the
instrumentation map file being provided to instead make the library
auto-detect the file type.

Reviewers: dblaikie

Subscribers: mgorny, varno, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293721 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 00:05:29 +00:00
Matt Arsenault
adb43778a7 InferAddressSpaces: Remove dead declaration
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293720 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 23:57:20 +00:00
Matt Arsenault
08e88e4167 InferAddressSpaces: Avoid double map lookup
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293719 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 23:48:44 +00:00
Matt Arsenault
34a0d5fe90 InferAddressSpaces: Fix broken casting of constants
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293718 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 23:48:40 +00:00
Matt Arsenault
e8b40414d3 AMDGPU: Fix warning
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293717 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 23:48:37 +00:00
Kyle Butt
5818a513ae CodeGen: Allow small copyable blocks to "break" the CFG.
When choosing the best successor for a block, ordinarily we would have preferred
a block that preserves the CFG unless there is a strong probability the other
direction. For small blocks that can be duplicated we now skip that requirement
as well, subject to some simple frequency calculations.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293716 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 23:48:32 +00:00
Rafael Espindola
8f159c8d92 Move more code to helper functions. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293715 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 23:26:32 +00:00
Justin Lebar
6f09ea3f57 [NVPTX] Compute approx sqrt as 1/rsqrt(x) rather than x*rsqrt(x).
x*rsqrt(x) returns NaN for x == 0, whereas 1/rsqrt(x) returns 0, as
desired.

Verified that the particular nvptx approximate instructions here do in
fact return 0 for x = 0.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293713 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 23:08:57 +00:00
Rafael Espindola
d99a5ea737 Move some code to a helper function. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293712 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 23:07:08 +00:00
Michael Kuperstein
eb0d431154 Shut up GCC warning about operator precedence. NFC.
Technically, this is actually changes the expression and the original
assert was "wrong", but since the conjunction is with true, it doesn't
matter in this case.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293709 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 22:48:45 +00:00
Daniel Berlin
07b87bc280 NewGVN: Dead argument cleanup
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293708 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 22:32:03 +00:00
Daniel Berlin
bb5c6551c0 NewGVN: Cleanup conditions to match reality
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293707 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 22:32:01 +00:00
Daniel Berlin
05b6b111d2 NewGVN: Add basic support for symbolic comparison evaluation
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293706 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 22:31:58 +00:00
Daniel Berlin
740306c544 NewGVN: Formatting cleanup after lookupOperandLeader change
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293705 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 22:31:56 +00:00
Daniel Berlin
dc4b13e22c NewGVN: Remove the unsued two arguments from lookupOperandLeader.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293704 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 22:31:53 +00:00
Daniel Berlin
e41f4f18c1 NewGVN: Cleanup header files we are using.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293703 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 22:31:50 +00:00
David Blaikie
fbad5bd691 Add a verbose/human readable mode to llvm-symbolizer to investigate discriminators and other line table/backtrace features
Patch by Simon Que!

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293697 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 22:19:38 +00:00
Daniel Berlin
c2913cb380 ScopedHashTable lookup should be const
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293695 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 22:01:08 +00:00
Davide Italiano
3ba2159d59 [NewGVN] Preserve TargetLibraryInfo analysis.
We can maybe preserve more but this is a first step.
Ack'ed by Danny on IRC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293694 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 21:53:18 +00:00
Dan Gohman
4d5536b101 [Utils] Update comment in vimrc
Fixed wrong paths in comments for *.vim files.

Patch By: Bruno Rosa (brunoalr)

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293693 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 21:33:21 +00:00
Davide Italiano
1e61910503 [Support] Add newline when dumping an APInt.
This annoyed me a few times but was lazy so I haven't fixed it
until today, when the output of my debugger was too confusing.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293691 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 21:26:18 +00:00
Rafael Espindola
adee6fda91 Make this file clang-format friendly and clang-format it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293689 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 21:11:12 +00:00
Taewook Oh
73b0db7269 Do not propagate DebugLoc across basic blocks
Summary:
DebugLoc shouldn't be propagated across basic blocks to prevent incorrect stepping and imprecise sample profile result. rL288903 addressed the wrong DebugLoc propagation issue by limiting the copy of DebugLoc when GVN removes a fully redundant load that is dominated by some other load. However, DebugLoc is still incorrectly propagated in the following example:


```
1:  extern int g;
2: 
3:  void foo(int x, int y, int z) {
4:    if (x)
5:      g = 0;
6:    else
7:      g = 1;
8:
9:    int i = 0;
10:   for ( ; i < y ; i++)
11:     if (i > z)
12:       g++;
13: }

```
Below is LLVM IR representation of the program before GVN:


```
@g = external local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define void @foo(i32 %x, i32 %y, i32 %z) local_unnamed_addr #0 !dbg !4 {
entry:
  %not.tobool = icmp eq i32 %x, 0, !dbg !8
  %.sink = zext i1 %not.tobool to i32, !dbg !8
  store i32 %.sink, i32* @g, align 4, !tbaa !9
  %cmp8 = icmp sgt i32 %y, 0, !dbg !13
  br i1 %cmp8, label %for.body.preheader, label %for.end, !dbg !17

for.body.preheader:                               ; preds = %entry
  br label %for.body, !dbg !19

for.body:                                         ; preds = %for.body.preheader, %for.inc
  %i.09 = phi i32 [ %inc4, %for.inc ], [ 0, %for.body.preheader ]
  %cmp1 = icmp sgt i32 %i.09, %z, !dbg !19
  br i1 %cmp1, label %if.then2, label %for.inc, !dbg !21

if.then2:                                         ; preds = %for.body
  %0 = load i32, i32* @g, align 4, !dbg !22, !tbaa !9
  %inc = add nsw i32 %0, 1, !dbg !22
  store i32 %inc, i32* @g, align 4, !dbg !22, !tbaa !9
  br label %for.inc, !dbg !23

for.inc:                                          ; preds = %for.body, %if.then2
  %inc4 = add nuw nsw i32 %i.09, 1, !dbg !24
  %exitcond = icmp ne i32 %inc4, %y, !dbg !13
  br i1 %exitcond, label %for.body, label %for.end.loopexit, !dbg !17

for.end.loopexit:                                 ; preds = %for.inc
  br label %for.end, !dbg !26

for.end:                                          ; preds = %for.end.loopexit, %entry
  ret void, !dbg !26
}

```
where 


```
!21 = !DILocation(line: 11, column: 9, scope: !15)
!22 = !DILocation(line: 12, column: 8, scope: !20)
!23 = !DILocation(line: 12, column: 7, scope: !20)
!24 = !DILocation(line: 10, column: 20, scope: !25)
```

And below is after GVN:


```
@g = external local_unnamed_addr global i32, align 4

define void @foo(i32 %x, i32 %y, i32 %z) local_unnamed_addr !dbg !4 {
entry:
  %not.tobool = icmp eq i32 %x, 0, !dbg !8
  %.sink = zext i1 %not.tobool to i32, !dbg !8
  store i32 %.sink, i32* @g, align 4, !tbaa !9
  %cmp8 = icmp sgt i32 %y, 0, !dbg !13
  br i1 %cmp8, label %for.body.preheader, label %for.end, !dbg !17

for.body.preheader:                               ; preds = %entry
  br label %for.body, !dbg !19

for.body:                                         ; preds = %for.inc, %for.body.preheader
  %0 = phi i32 [ %1, %for.inc ], [ %.sink, %for.body.preheader ], !dbg !21
  %i.09 = phi i32 [ %inc4, %for.inc ], [ 0, %for.body.preheader ]
  %cmp1 = icmp sgt i32 %i.09, %z, !dbg !19
  br i1 %cmp1, label %if.then2, label %for.inc, !dbg !22

if.then2:                                         ; preds = %for.body
  %inc = add nsw i32 %0, 1, !dbg !21
  store i32 %inc, i32* @g, align 4, !dbg !21, !tbaa !9
  br label %for.inc, !dbg !23

for.inc:                                          ; preds = %if.then2, %for.body
  %1 = phi i32 [ %inc, %if.then2 ], [ %0, %for.body ]
  %inc4 = add nuw nsw i32 %i.09, 1, !dbg !24
  %exitcond = icmp ne i32 %inc4, %y, !dbg !13
  br i1 %exitcond, label %for.body, label %for.end.loopexit, !dbg !17

for.end.loopexit:                                 ; preds = %for.inc
  br label %for.end, !dbg !26

for.end:                                          ; preds = %for.end.loopexit, %entry
  ret void, !dbg !26
}

```
As you see, GVN removes the load in if.then2 block and creates a phi instruction in for.body for it. The problem is that DebugLoc of remove load instruction is propagated to the newly created phi instruction, which is wrong. rL288903 cannot handle this case because ValuesPerBlock.size() is not 1 in this example when the load is removed.

Reviewers: aprantl, andreadb, wolfgangp

Reviewed By: andreadb

Subscribers: davide, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293688 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 20:57:13 +00:00