Index: llvm/lib/Analysis/Loads.cpp =================================================================== --- llvm/lib/Analysis/Loads.cpp +++ llvm/lib/Analysis/Loads.cpp @@ -498,12 +498,15 @@ if (!AreEquivalentAddressValues(StorePtr, Ptr)) return nullptr; + if (IsLoadCSE) + *IsLoadCSE = false; + Value *Val = SI->getValueOperand(); - if (CastInst::isBitOrNoopPointerCastable(Val->getType(), AccessTy, DL)) { - if (IsLoadCSE) - *IsLoadCSE = false; + if (CastInst::isBitOrNoopPointerCastable(Val->getType(), AccessTy, DL)) return Val; - } + + if (auto *C = dyn_cast(Val)) + return ConstantFoldLoadThroughBitcast(C, AccessTy, DL); } return nullptr; Index: llvm/test/Transforms/InstCombine/load-store-forward.ll =================================================================== --- llvm/test/Transforms/InstCombine/load-store-forward.ll +++ llvm/test/Transforms/InstCombine/load-store-forward.ll @@ -22,8 +22,7 @@ ; CHECK-LABEL: @vec_store_load_first( ; CHECK-NEXT: [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>* ; CHECK-NEXT: store <2 x i32> , <2 x i32>* [[P2]], align 8 -; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[P]], align 4 -; CHECK-NEXT: ret i32 [[LOAD]] +; CHECK-NEXT: ret i32 1 ; %p2 = bitcast i32* %p to <2 x i32>* store <2 x i32> , <2 x i32>* %p2