diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index c0a31e3bdca9c3..04983ac39d0539 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -2228,6 +2228,7 @@ static Value *isSafeToSpeculateStore(Instruction *I, BasicBlock *BrBB, return nullptr; Value *StorePtr = StoreToHoist->getPointerOperand(); + Type *StoreTy = StoreToHoist->getValueOperand()->getType(); // Look for a store to the same pointer in BrBB. unsigned MaxNumInstToLookAt = 9; @@ -2244,7 +2245,8 @@ static Value *isSafeToSpeculateStore(Instruction *I, BasicBlock *BrBB, if (auto *SI = dyn_cast(&CurI)) { // Found the previous store make sure it stores to the same location. - if (SI->getPointerOperand() == StorePtr) + if (SI->getPointerOperand() == StorePtr && + SI->getValueOperand()->getType() == StoreTy) // Found the previous store, return its value operand. return SI->getValueOperand(); return nullptr; // Unknown store. diff --git a/llvm/test/Transforms/SimplifyCFG/speculate-store.ll b/llvm/test/Transforms/SimplifyCFG/speculate-store.ll index 27c9ed5f2e77a3..6d08d3cd32fe6f 100644 --- a/llvm/test/Transforms/SimplifyCFG/speculate-store.ll +++ b/llvm/test/Transforms/SimplifyCFG/speculate-store.ll @@ -112,6 +112,27 @@ ret.end: ret void } +define void @different_type(ptr %ptr, i1 %cmp) { +; CHECK-LABEL: @different_type( +; CHECK-NEXT: store i32 0, ptr [[PTR:%.*]], align 4 +; CHECK-NEXT: br i1 [[CMP:%.*]], label [[IF_THEN:%.*]], label [[RET_END:%.*]] +; CHECK: if.then: +; CHECK-NEXT: store i64 1, ptr [[PTR]], align 4 +; CHECK-NEXT: br label [[RET_END]] +; CHECK: ret.end: +; CHECK-NEXT: ret void +; + store i32 0, ptr %ptr + br i1 %cmp, label %if.then, label %ret.end + +if.then: + store i64 1, ptr %ptr + br label %ret.end + +ret.end: + ret void +} + ; CHECK: !0 = !{!"branch_weights", i32 3, i32 5} !0 = !{!"branch_weights", i32 3, i32 5}