diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -1987,7 +1987,11 @@ if (SkipStores.contains(Def) || MSSA.isLiveOnEntryDef(Def) || !isRemovable(Def->getMemoryInst())) continue; - auto *UpperDef = dyn_cast(Def->getDefiningAccess()); + MemoryDef *UpperDef; + if (Def->isOptimized()) + UpperDef = dyn_cast(Def->getOptimized()); + else + UpperDef = dyn_cast(Def->getDefiningAccess()); if (!UpperDef || MSSA.isLiveOnEntryDef(UpperDef)) continue; diff --git a/llvm/test/Transforms/DeadStoreElimination/stores-of-existing-values.ll b/llvm/test/Transforms/DeadStoreElimination/stores-of-existing-values.ll --- a/llvm/test/Transforms/DeadStoreElimination/stores-of-existing-values.ll +++ b/llvm/test/Transforms/DeadStoreElimination/stores-of-existing-values.ll @@ -324,7 +324,6 @@ ; CHECK: bb2: ; CHECK-NEXT: ret void ; CHECK: bb3: -; CHECK-NEXT: store i32 0, i32* [[P]], align 4 ; CHECK-NEXT: ret void ; store i32 0, i32* %P @@ -416,8 +415,6 @@ ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[PTR:%.*]], i8 0, i64 10, i1 false) ; CHECK-NEXT: [[PTR_4:%.*]] = getelementptr i8, i8* [[PTR]], i64 4 ; CHECK-NEXT: store i8 8, i8* [[PTR_4]], align 1 -; CHECK-NEXT: [[PTR_5:%.*]] = getelementptr i8, i8* [[PTR]], i64 5 -; CHECK-NEXT: store i8 0, i8* [[PTR_5]], align 1 ; CHECK-NEXT: ret void ; call void @llvm.memset.p0i8.i64(i8* %ptr, i8 0, i64 10, i1 false) @@ -506,8 +503,8 @@ define void @test14_strcat(i8* noalias %P, i8* noalias %Q) { ; CHECK-LABEL: @test14_strcat( -; CHECK-NEXT: call i8* @strcat(i8* [[P:%.*]], i8* [[Q:%.*]]) -; CHECK-NEXT: call i8* @strcat(i8* [[P]], i8* [[Q]]) +; CHECK-NEXT: [[CALL1:%.*]] = call i8* @strcat(i8* [[P:%.*]], i8* [[Q:%.*]]) +; CHECK-NEXT: [[CALL2:%.*]] = call i8* @strcat(i8* [[P]], i8* [[Q]]) ; CHECK-NEXT: ret void ; %call1 = call i8* @strcat(i8* %P, i8* %Q)