[llvm] r304937 - [Hexagon] Generate 'inbounds' GEPs in HexagonCommonGEP

Krzysztof Parzyszek via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 7 13:04:34 PDT 2017


Author: kparzysz
Date: Wed Jun  7 15:04:33 2017
New Revision: 304937

URL: http://llvm.org/viewvc/llvm-project?rev=304937&view=rev
Log:
[Hexagon] Generate 'inbounds' GEPs in HexagonCommonGEP

Added:
    llvm/trunk/test/CodeGen/Hexagon/common-gep-inbounds.ll
Modified:
    llvm/trunk/lib/Target/Hexagon/HexagonCommonGEP.cpp

Modified: llvm/trunk/lib/Target/Hexagon/HexagonCommonGEP.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonCommonGEP.cpp?rev=304937&r1=304936&r2=304937&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/HexagonCommonGEP.cpp (original)
+++ llvm/trunk/lib/Target/Hexagon/HexagonCommonGEP.cpp Wed Jun  7 15:04:33 2017
@@ -175,7 +175,8 @@ namespace {
       None      = 0,
       Root      = 0x01,
       Internal  = 0x02,
-      Used      = 0x04
+      Used      = 0x04,
+      InBounds  = 0x08
     };
 
     uint32_t Flags;
@@ -231,6 +232,11 @@ namespace {
         OS << ',';
       OS << "used";
     }
+    if (GN.Flags & GepNode::InBounds) {
+      if (Comma)
+        OS << ',';
+      OS << "inbounds";
+    }
     OS << "} ";
     if (GN.Flags & GepNode::Root)
       OS << "BaseVal:" << GN.BaseVal->getName() << '(' << GN.BaseVal << ')';
@@ -334,10 +340,11 @@ void HexagonCommonGEP::processGepInst(Ge
   DEBUG(dbgs() << "Visiting GEP: " << *GepI << '\n');
   GepNode *N = new (*Mem) GepNode;
   Value *PtrOp = GepI->getPointerOperand();
+  uint32_t InBounds = GepI->isInBounds() ? GepNode::InBounds : 0;
   ValueToNodeMap::iterator F = NM.find(PtrOp);
   if (F == NM.end()) {
     N->BaseVal = PtrOp;
-    N->Flags |= GepNode::Root;
+    N->Flags |= GepNode::Root | InBounds;
   } else {
     // If PtrOp was a GEP instruction, it must have already been processed.
     // The ValueToNodeMap entry for it is the last gep node in the generated
@@ -373,7 +380,7 @@ void HexagonCommonGEP::processGepInst(Ge
     Value *Op = *OI;
     GepNode *Nx = new (*Mem) GepNode;
     Nx->Parent = PN;  // Link Nx to the previous node.
-    Nx->Flags |= GepNode::Internal;
+    Nx->Flags |= GepNode::Internal | InBounds;
     Nx->PTy = PtrTy;
     Nx->Idx = Op;
     Nodes.push_back(Nx);
@@ -1081,7 +1088,7 @@ Value *HexagonCommonGEP::fabricateGEP(No
   GepNode *RN = NA[0];
   assert((RN->Flags & GepNode::Root) && "Creating GEP for non-root");
 
-  Value *NewInst = nullptr;
+  GetElementPtrInst *NewInst = nullptr;
   Value *Input = RN->BaseVal;
   Value **IdxList = new Value*[Num+1];
   unsigned nax = 0;
@@ -1112,6 +1119,7 @@ Value *HexagonCommonGEP::fabricateGEP(No
     Type *InpTy = Input->getType();
     Type *ElTy = cast<PointerType>(InpTy->getScalarType())->getElementType();
     NewInst = GetElementPtrInst::Create(ElTy, Input, A, "cgep", &*At);
+    NewInst->setIsInBounds(RN->Flags & GepNode::InBounds);
     DEBUG(dbgs() << "new GEP: " << *NewInst << '\n');
     Input = NewInst;
   } while (nax <= Num);

Added: llvm/trunk/test/CodeGen/Hexagon/common-gep-inbounds.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Hexagon/common-gep-inbounds.ll?rev=304937&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Hexagon/common-gep-inbounds.ll (added)
+++ llvm/trunk/test/CodeGen/Hexagon/common-gep-inbounds.ll Wed Jun  7 15:04:33 2017
@@ -0,0 +1,20 @@
+; RUN: llc -march=hexagon -debug-only=commgep 2>&1 < %s | FileCheck %s
+; REQUIRES: asserts
+
+; We should generate new GEPs with "inbounds" flag.
+; CHECK: new GEP:{{.*}}inbounds
+; CHECK: new GEP:{{.*}}inbounds
+
+target triple = "hexagon"
+
+%struct.0 = type { i16, i16 }
+
+; Function Attrs: nounwind
+define i16 @TraceBack() #0 {
+entry:
+  %p = getelementptr inbounds %struct.0, %struct.0* undef, i32 0, i32 0
+  %a = load i16, i16* %p
+  ret i16 %a
+}
+
+attributes #0 = { nounwind "target-cpu"="hexagonv60" "target-features"="-hvx-double,-long-calls" }




More information about the llvm-commits mailing list