Based on the design doc at
it handles non-member const objects.
Extensions are discussed in the design doc and will be submitted separately.
Your D14419 removes a lot of the code added here. Can you update this patch to not add that code? I'd prefer not to review the portion of this code that you're about to delete.
The call to AddInitializerToStaticVarDecl above indirectly calls EmitCXXGlobalVarDeclInit, which already emits an llvm.invariant.start call when appropriate. Please extend the code in EmitCXXGlobalVarDeclInit to handle these new cases (constant types with non-trivial destructors) rather adding another codepath that creates an llvm.invariant.start here.
I don't think this check is necessary; if we know some region of memory is locally constant, I don't think it matters whether we can trace it back to an alloca.
Do we need to add QualType::isWriteOnce for this? CodeGenModule::isTypeConstant seems to be doing mostly the right set of checks. I suggest you add a new flag to it to indicate whether it should check for trivial destructibility, and then use it here instead of using isWriteOnce.
The use of RAII here seems unnecessary. You should be able to emit the invariant start and the invariant end cleanup at the same time, by moving this after the call to EmitAutoVarCleanups.
This conditional should not be necessary: IRBuilder::CreateBitCast should choose between a bitcast constant and a bitcast instruction for you. Just use the non-constant branch in all cases.
Not all of our supported versions of MSVC accept this syntax. Create a separate array of llvm::Value * and pass it in here.
This should be unnecessary if you let EmitCXXGlobalVarDeclInit emit the invariant start.
Please also check that @llvm.invariant.end is called later in the same global initialization function.
Likewise for this case.