Skip to content

Commit 930a687

Browse files
committed
[Loads] Check type size in bits during store to load forwarding
Rather than checking the rounded type store size, check the type size in bits. We don't want to forward a store of i1 to a load of i8 for example, even though they have the same type store size. The padding bits have unspecified contents. This is a partial fix for the issue reported at https://reviews.llvm.org/D115924#inline-1179482, the problem also needs to be addressed more generally in the constant folding code.
1 parent 29fe998 commit 930a687

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

llvm/lib/Analysis/Loads.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,8 @@ static Value *getAvailableLoadStore(Instruction *Inst, const Value *Ptr,
504504
if (CastInst::isBitOrNoopPointerCastable(Val->getType(), AccessTy, DL))
505505
return Val;
506506

507-
TypeSize StoreSize = DL.getTypeStoreSize(Val->getType());
508-
TypeSize LoadSize = DL.getTypeStoreSize(AccessTy);
507+
TypeSize StoreSize = DL.getTypeSizeInBits(Val->getType());
508+
TypeSize LoadSize = DL.getTypeSizeInBits(AccessTy);
509509
if (TypeSize::isKnownLE(LoadSize, StoreSize))
510510
if (auto *C = dyn_cast<Constant>(Val))
511511
return ConstantFoldLoadFromConst(C, AccessTy, DL);

llvm/test/Transforms/InstCombine/load-store-forward.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,9 @@ entry:
293293
define i8 @load_i8_store_i1(i1* %a) {
294294
; CHECK-LABEL: @load_i8_store_i1(
295295
; CHECK-NEXT: store i1 true, i1* [[A:%.*]], align 1
296-
; CHECK-NEXT: ret i8 -1
296+
; CHECK-NEXT: [[A_I8:%.*]] = bitcast i1* [[A]] to i8*
297+
; CHECK-NEXT: [[V:%.*]] = load i8, i8* [[A_I8]], align 1
298+
; CHECK-NEXT: ret i8 [[V]]
297299
;
298300
store i1 true, i1* %a
299301
%a.i8 = bitcast i1* %a to i8*

0 commit comments

Comments
 (0)