[llvm] b7585a0 - [Bitcode] Enumerate constexpr GEP source element type in initializer

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 11 07:39:05 PST 2022


Author: Nikita Popov
Date: 2022-03-11T16:38:58+01:00
New Revision: b7585a08d5dfcc5bb85f00632f7cf8f2924036d8

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

LOG: [Bitcode] Enumerate constexpr GEP source element type in initializer

The constexpr source element type was enumerated if the GEP was
used as part of an instruction. However, things like global
initializers go through a different code path, and we need to
enumerate the type there as well.

Added: 
    

Modified: 
    llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
    llvm/test/Assembler/opaque-ptr.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
index 01f7e85bd60ed..18157d57dcb9a 100644
--- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
+++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
@@ -939,9 +939,12 @@ void ValueEnumerator::EnumerateValue(const Value *V) {
            I != E; ++I)
         if (!isa<BasicBlock>(*I)) // Don't enumerate BB operand to BlockAddress.
           EnumerateValue(*I);
-      if (auto *CE = dyn_cast<ConstantExpr>(C))
+      if (auto *CE = dyn_cast<ConstantExpr>(C)) {
         if (CE->getOpcode() == Instruction::ShuffleVector)
           EnumerateValue(CE->getShuffleMaskForBitcode());
+        if (auto *GEP = dyn_cast<GEPOperator>(CE))
+          EnumerateType(GEP->getSourceElementType());
+      }
 
       // Finally, add the value.  Doing this could make the ValueID reference be
       // dangling, don't reuse it.

diff  --git a/llvm/test/Assembler/opaque-ptr.ll b/llvm/test/Assembler/opaque-ptr.ll
index c4171fa778a5d..9c4c738703715 100644
--- a/llvm/test/Assembler/opaque-ptr.ll
+++ b/llvm/test/Assembler/opaque-ptr.ll
@@ -4,6 +4,9 @@
 ; CHECK: @global = external global ptr
 @global = external global ptr
 
+; CHECK: @global_const_gep = global ptr getelementptr inbounds (i47, ptr @global, i64 1)
+ at global_const_gep = global ptr getelementptr (i47, ptr @global, i64 1)
+
 ; CHECK: @fptr1 = external global ptr
 ; CHECK: @fptr2 = external global ptr addrspace(1)
 ; CHECK: @fptr3 = external global ptr addrspace(2)


        


More information about the llvm-commits mailing list