Index: lib/Transforms/Utils/SimplifyCFG.cpp =================================================================== --- lib/Transforms/Utils/SimplifyCFG.cpp +++ lib/Transforms/Utils/SimplifyCFG.cpp @@ -2966,6 +2966,14 @@ PStore->getAAMetadata(AAMD, /*Merge=*/false); PStore->getAAMetadata(AAMD, /*Merge=*/true); SI->setAAMetadata(AAMD); + unsigned PAlignment = PStore->getAlignment(); + unsigned QAlignment = QStore->getAlignment(); + if (unsigned MinAlignment = std::min(PAlignment, QAlignment)) + // Choose the minimum of all non-zero alignments. + SI->setAlignment(MinAlignment); + else if (unsigned MaxAlignment = std::max(PAlignment, QAlignment)) + // Choose the first non-zero alignment, if any. + SI->setAlignment(MaxAlignment); QStore->eraseFromParent(); PStore->eraseFromParent(); Index: test/Transforms/SimplifyCFG/preserve-store-alignment.ll =================================================================== --- test/Transforms/SimplifyCFG/preserve-store-alignment.ll +++ test/Transforms/SimplifyCFG/preserve-store-alignment.ll @@ -25,7 +25,7 @@ ; CHECK-NEXT: [[TMP7:%.*]] = xor i1 [[TOBOOL5]], true ; CHECK-NEXT: [[TMP8:%.*]] = or i1 [[TMP6]], [[TMP7]] ; CHECK-NEXT: br i1 [[TMP8]], label [[TMP9:%.*]], label [[TMP10:%.*]] -; CHECK: store <2 x i64> [[DOT]], <2 x i64>* bitcast (i64* getelementptr inbounds (%struct.Counters, %struct.Counters* @counters, i64 0, i32 1) to <2 x i64>*) +; CHECK: store <2 x i64> [[DOT]], <2 x i64>* bitcast (i64* getelementptr inbounds (%struct.Counters, %struct.Counters* @counters, i64 0, i32 1) to <2 x i64>*), align 8 ; CHECK-NEXT: br label [[TMP10]] ; CHECK: ret i32 0 ;