llvmorg-22-init-1937-g2672719a09cf.patch (2170B)
1 From ce610275edfd05704d5058716a971c2003299b95 Mon Sep 17 00:00:00 2001 2 From: Nikita Popov <npopov@redhat.com> 3 Date: Wed, 30 Jul 2025 17:52:08 +0200 4 Subject: [PATCH 1/2] [InstCombine] Don't handle non-canonical index type in 5 icmp of load fold (#151346) 6 7 We should just bail out and wait for it to be canonicalized. The current 8 implementation could emit a trunc without actually performing the 9 transform. 10 --- 11 .../InstCombine/InstCombineCompares.cpp | 16 +++++----------- 12 1 file changed, 5 insertions(+), 11 deletions(-) 13 14 diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp 15 index 810ce7d382ae..19dd71355622 100644 16 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp 17 +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp 18 @@ -161,6 +161,11 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal( 19 LaterIndices.push_back(IdxVal); 20 } 21 22 + Value *Idx = GEP->getOperand(2); 23 + // If the index type is non-canonical, wait for it to be canonicalized. 24 + if (Idx->getType() != DL.getIndexType(GEP->getType())) 25 + return nullptr; 26 + 27 enum { Overdefined = -3, Undefined = -2 }; 28 29 // Variables for our state machines. 30 @@ -288,17 +293,6 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal( 31 32 // Now that we've scanned the entire array, emit our new comparison(s). We 33 // order the state machines in complexity of the generated code. 34 - Value *Idx = GEP->getOperand(2); 35 - 36 - // If the index is larger than the pointer offset size of the target, truncate 37 - // the index down like the GEP would do implicitly. We don't have to do this 38 - // for an inbounds GEP because the index can't be out of range. 39 - if (!GEP->isInBounds()) { 40 - Type *PtrIdxTy = DL.getIndexType(GEP->getType()); 41 - unsigned OffsetSize = PtrIdxTy->getIntegerBitWidth(); 42 - if (Idx->getType()->getPrimitiveSizeInBits().getFixedValue() > OffsetSize) 43 - Idx = Builder.CreateTrunc(Idx, PtrIdxTy); 44 - } 45 46 // If inbounds keyword is not present, Idx * ElementSize can overflow. 47 // Let's assume that ElementSize is 2 and the wanted value is at offset 0. 48 -- 49 2.51.0