Index: lib/Analysis/ConstantFolding.cpp =================================================================== --- lib/Analysis/ConstantFolding.cpp +++ lib/Analysis/ConstantFolding.cpp @@ -1206,6 +1206,10 @@ C = C->getAggregateElement(CE->getOperand(i)); if (!C) return nullptr; + + // Don't step through empty types. The aliasing is too hard to figure out. + if (C->getType()->isEmptyTy()) + return nullptr; } return C; } @@ -1222,6 +1226,10 @@ C = C->getAggregateElement(Indices[i]); if (!C) return nullptr; + + // Don't step through empty types. The aliasing is too hard to figure out. + if (C->getType()->isEmptyTy()) + return nullptr; } return C; } Index: test/Transforms/GlobalOpt/empty-type-field.ll =================================================================== --- test/Transforms/GlobalOpt/empty-type-field.ll +++ test/Transforms/GlobalOpt/empty-type-field.ll @@ -0,0 +1,19 @@ +; RUN: opt < %s -S -globalopt | FileCheck %s + +; ModuleID = 'bugpoint-passinput.bc' +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +%struct.qux = type { [0 x double], double } + +@qux = internal global %struct.qux { [0 x double] zeroinitializer, double 4.053854e+04 }, align 8 + +define void @foo() { +entry: + %0 = load double* getelementptr inbounds (%struct.qux* @qux, i32 0, i32 0, i32 0), align 1 + call void @bar(double %0) +; CHECK-NOT: @bar(double 0.000000e+00) + ret void +} + +declare void @bar(double) \ No newline at end of file