[llvm] 30d7121 - [InstCombine] Use replaceOperand() API in GEP transforms

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 28 11:07:48 PDT 2020


Author: Nikita Popov
Date: 2020-03-28T19:07:25+01:00
New Revision: 30d712103faa8c78e8b1dbc9cc6c9b831bb20e4c

URL: https://github.com/llvm/llvm-project/commit/30d712103faa8c78e8b1dbc9cc6c9b831bb20e4c
DIFF: https://github.com/llvm/llvm-project/commit/30d712103faa8c78e8b1dbc9cc6c9b831bb20e4c.diff

LOG: [InstCombine] Use replaceOperand() API in GEP transforms

To make sure that replaced operands get DCEd. This drops one
iteration from gepphigep.ll, which is still not optimal.

This was the last test case performing more than 3 iterations.

NFC-ish, only worklist order should change.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
    llvm/test/Transforms/InstCombine/gepphigep.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 49e39c3bc87a..2e71f5a9ef48 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1996,7 +1996,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
 
     GEP.getParent()->getInstList().insert(
         GEP.getParent()->getFirstInsertionPt(), NewGEP);
-    GEP.setOperand(0, NewGEP);
+    replaceOperand(GEP, 0, NewGEP);
     PtrOp = NewGEP;
   }
 
@@ -2096,8 +2096,8 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
       // Update the GEP in place if possible.
       if (Src->getNumOperands() == 2) {
         GEP.setIsInBounds(isMergedGEPInBounds(*Src, *cast<GEPOperator>(&GEP)));
-        GEP.setOperand(0, Src->getOperand(0));
-        GEP.setOperand(1, Sum);
+        replaceOperand(GEP, 0, Src->getOperand(0));
+        replaceOperand(GEP, 1, Sum);
         return &GEP;
       }
       Indices.append(Src->op_begin()+1, Src->op_end()-1);
@@ -2215,9 +2215,8 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
             // array.  Because the array type is never stepped over (there
             // is a leading zero) we can fold the cast into this GEP.
             if (StrippedPtrTy->getAddressSpace() == GEP.getAddressSpace()) {
-              GEP.setOperand(0, StrippedPtr);
               GEP.setSourceElementType(XATy);
-              return &GEP;
+              return replaceOperand(GEP, 0, StrippedPtr);
             }
             // Cannot replace the base pointer directly because StrippedPtr's
             // address space is 
diff erent. Instead, create a new GEP followed by

diff  --git a/llvm/test/Transforms/InstCombine/gepphigep.ll b/llvm/test/Transforms/InstCombine/gepphigep.ll
index cc90d714be73..7d3fe949ede2 100644
--- a/llvm/test/Transforms/InstCombine/gepphigep.ll
+++ b/llvm/test/Transforms/InstCombine/gepphigep.ll
@@ -1,4 +1,4 @@
-; RUN: opt -instcombine -S  < %s | FileCheck %s
+; RUN: opt -instcombine -instcombine-infinite-loop-threshold=3 -S < %s | FileCheck %s
 
 %struct1 = type { %struct2*, i32, i32, i32 }
 %struct2 = type { i32, i32 }


        


More information about the llvm-commits mailing list