Index: lib/Analysis/ConstantFolding.cpp =================================================================== --- lib/Analysis/ConstantFolding.cpp +++ lib/Analysis/ConstantFolding.cpp @@ -532,6 +532,10 @@ if (GV->isConstant() && GV->hasDefinitiveInitializer()) return GV->getInitializer(); + if (auto *GA = dyn_cast(C)) + if (GA->getAliasee() && !GA->mayBeOverridden()) + return ConstantFoldLoadFromConstPtr(GA->getAliasee(), DL); + // If the loaded value isn't a constant expr, we can't handle it. ConstantExpr *CE = dyn_cast(C); if (!CE) Index: test/Analysis/ConstantFolding/global-alias-constprop.ll =================================================================== --- test/Analysis/ConstantFolding/global-alias-constprop.ll +++ test/Analysis/ConstantFolding/global-alias-constprop.ll @@ -0,0 +1,11 @@ +; RUN: opt < %s -sccp -S | FileCheck %s + +@0 = private unnamed_addr constant [2 x i32] [i32 -1, i32 1] +@"\01??_7A@@6B@" = unnamed_addr alias getelementptr inbounds ([2 x i32], [2 x i32]* @0, i32 0, i32 1) + +; CHECK: ret i32 1 + +define i32 @main() { + %a = load i32, i32* @"\01??_7A@@6B@" + ret i32 %a +}