[llvm] 930bc6c - [InstCombine] Avoid use of ConstantExpr::getSExtOrTrunc()

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 1 08:11:06 PDT 2023


Author: Nikita Popov
Date: 2023-11-01T16:10:57+01:00
New Revision: 930bc6c7b5f3d1c3a4f2f1a09414700aab526f17

URL: https://github.com/llvm/llvm-project/commit/930bc6c7b5f3d1c3a4f2f1a09414700aab526f17
DIFF: https://github.com/llvm/llvm-project/commit/930bc6c7b5f3d1c3a4f2f1a09414700aab526f17.diff

LOG: [InstCombine] Avoid use of ConstantExpr::getSExtOrTrunc()

InstCombine will canonicalize the index type, no need to handle
the non-canonical case.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 2ff27abc79318c4..7574987d0e23141 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -668,11 +668,11 @@ getAsConstantIndexedAddress(Type *ElemTy, Value *V, const DataLayout &DL) {
       if (!GEP->isInBounds())
         break;
       if (GEP->hasAllConstantIndices() && GEP->getNumIndices() == 1 &&
-          GEP->getSourceElementType() == ElemTy) {
+          GEP->getSourceElementType() == ElemTy &&
+          GEP->getOperand(1)->getType() == IndexType) {
         V = GEP->getOperand(0);
         Constant *GEPIndex = static_cast<Constant *>(GEP->getOperand(1));
-        Index = ConstantExpr::getAdd(
-            Index, ConstantExpr::getSExtOrTrunc(GEPIndex, IndexType));
+        Index = ConstantExpr::getAdd(Index, GEPIndex);
         continue;
       }
       break;


        


More information about the llvm-commits mailing list