[llvm-bugs] [Bug 28874] New: GVN hoists a store across a load

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Aug 5 13:09:43 PDT 2016


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

            Bug ID: 28874
           Summary: GVN hoists a store across a load
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: kparzysz at codeaurora.org
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Run with:
opt -mtriple=hexagon -gvn-hoist -S < gvnhoist.ll


Before GVN hoist, if.then468 contains these instructions (abbreviated):
  %arrayidx473 = ...
  %.t104 = load i32, i32* %arrayidx473, align 4, !tbaa !7
  ...
  store i32 0, i32* %arrayidx473, align 4, !tbaa !7

That is, the load happens before the store. There is another store that happens
on the other side of the conditional branch so the fact that is moves a store
from a side node is not a problem.  After GVN hoist, the store is moved up to
for.body463 and now happens before the load.



Code before GVN hoist:

for.body463:                                      ; preds = %for.cond460
  %.t464 = getelementptr inbounds %struct.s0, %struct.s0* %s0, i32 0, i32 20
  %arrayidx465 = getelementptr inbounds [6 x i32], [6 x i32]* %.t464, i32 0,
i32 %n.4
  %.t102 = load i32, i32* %arrayidx465, align 4, !tbaa !7
  %and466 = and i32 %.t102, 32768
  %tobool467 = icmp ne i32 %and466, 0
  br i1 %tobool467, label %if.then468, label %if.else573

if.then468:                                       ; preds = %for.body463
  %.d1 = getelementptr inbounds %struct.s0, %struct.s0* %s0, i32 0, i32 125
  %.t103 = load i16, i16* %.d1, align 4, !tbaa !31
  %conv469 = sext i16 %.t103 to i32
  %arrayidx470 = getelementptr inbounds [6 x %struct.s1], [6 x %struct.s1]*
@s1, i32 0, i32 %n.4
  %.t471 = getelementptr inbounds %struct.s1, %struct.s1* %arrayidx470, i32 0,
i32 62
  %arrayidx472 = getelementptr inbounds [7 x [32 x i32]], [7 x [32 x i32]]*
%.t471, i32 0, i32 1
  %arrayidx473 = getelementptr inbounds [32 x i32], [32 x i32]* %arrayidx472,
i32 0, i32 %.t2
  %.t104 = load i32, i32* %arrayidx473, align 4, !tbaa !7
  %mul474 = mul nsw i32 %conv469, %.t104
  %arrayidx479 = getelementptr inbounds [7 x [32 x i32]], [7 x [32 x i32]]*
%.t471, i32 0, i32 2
  %arrayidx480 = getelementptr inbounds [32 x i32], [32 x i32]* %arrayidx479,
i32 0, i32 %.t2
  %.t105 = load i32, i32* %arrayidx480, align 4, !tbaa !7
  %mul481 = mul nsw i32 %conv469, %.t105
  store i32 0, i32* %arrayidx473, align 4, !tbaa !7
  store i32 0, i32* %arrayidx480, align 4, !tbaa !7
  %.q1 = getelementptr inbounds %struct.s0, %struct.s0* %s0, i32 0, i32 126
  %.t106 = load i16, i16* %.q1, align 2, !tbaa !32
  %conv490 = sext i16 %.t106 to i32
  %or491 = or i32 16, %.t2


After GVN hoist:

for.body463:                                      ; preds = %for.cond460
  %.t464 = getelementptr inbounds %struct.s0, %struct.s0* %s0, i32 0, i32 20
  %arrayidx465 = getelementptr inbounds [6 x i32], [6 x i32]* %.t464, i32 0,
i32 %n.4
  %.t102 = load i32, i32* %arrayidx465, align 4, !tbaa !6
  %and466 = and i32 %.t102, 32768
  %tobool467 = icmp ne i32 %and466, 0
  %or491 = or i32 16, %.t2
  %0 = getelementptr inbounds [6 x %struct.s1], [6 x %struct.s1]* @s1, i32 0,
i32 %n.4
  %1 = getelementptr inbounds %struct.s1, %struct.s1* %0, i32 0, i32 62
  %2 = getelementptr inbounds [7 x [32 x i32]], [7 x [32 x i32]]* %1, i32 0,
i32 1
  %3 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i32 0, i32 %.t2
  store i32 0, i32* %3, align 4, !tbaa !6
  br i1 %tobool467, label %if.then468, label %if.else573

if.then468:                                       ; preds = %for.body463
  %.d1 = getelementptr inbounds %struct.s0, %struct.s0* %s0, i32 0, i32 125
  %.t103 = load i16, i16* %.d1, align 4, !tbaa !7
  %conv469 = sext i16 %.t103 to i32
  %arrayidx470 = getelementptr inbounds [6 x %struct.s1], [6 x %struct.s1]*
@s1, i32 0, i32 %n.4
  %.t471 = getelementptr inbounds %struct.s1, %struct.s1* %arrayidx470, i32 0,
i32 62
  %arrayidx472 = getelementptr inbounds [7 x [32 x i32]], [7 x [32 x i32]]*
%.t471, i32 0, i32 1
  %arrayidx473 = getelementptr inbounds [32 x i32], [32 x i32]* %arrayidx472,
i32 0, i32 %.t2
  %.t104 = load i32, i32* %arrayidx473, align 4, !tbaa !6
  %mul474 = mul nsw i32 %conv469, %.t104
  %arrayidx479 = getelementptr inbounds [7 x [32 x i32]], [7 x [32 x i32]]*
%.t471, i32 0, i32 2
  %arrayidx480 = getelementptr inbounds [32 x i32], [32 x i32]* %arrayidx479,
i32 0, i32 %.t2
  %.t105 = load i32, i32* %arrayidx480, align 4, !tbaa !6
  %mul481 = mul nsw i32 %conv469, %.t105
  store i32 0, i32* %arrayidx480, align 4, !tbaa !6
  %.q1 = getelementptr inbounds %struct.s0, %struct.s0* %s0, i32 0, i32 126
  %.t106 = load i16, i16* %.q1, align 2, !tbaa !8
  %conv490 = sext i16 %.t106 to i32

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160805/46d2ea03/attachment.html>


More information about the llvm-bugs mailing list