[llvm] 930a687 - [Loads] Check type size in bits during store to load forwarding

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 8 08:29:38 PDT 2022


Author: Nikita Popov
Date: 2022-04-08T17:29:29+02:00
New Revision: 930a68765dff96927d706d258ef0c2ad9c7ec2ab

URL: https://github.com/llvm/llvm-project/commit/930a68765dff96927d706d258ef0c2ad9c7ec2ab
DIFF: https://github.com/llvm/llvm-project/commit/930a68765dff96927d706d258ef0c2ad9c7ec2ab.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Analysis/Loads.cpp
    llvm/test/Transforms/InstCombine/load-store-forward.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp
index fafd95ecc48f3..bc1d82cf14806 100644
--- a/llvm/lib/Analysis/Loads.cpp
+++ b/llvm/lib/Analysis/Loads.cpp
@@ -504,8 +504,8 @@ static Value *getAvailableLoadStore(Instruction *Inst, const Value *Ptr,
     if (CastInst::isBitOrNoopPointerCastable(Val->getType(), AccessTy, DL))
       return Val;
 
-    TypeSize StoreSize = DL.getTypeStoreSize(Val->getType());
-    TypeSize LoadSize = DL.getTypeStoreSize(AccessTy);
+    TypeSize StoreSize = DL.getTypeSizeInBits(Val->getType());
+    TypeSize LoadSize = DL.getTypeSizeInBits(AccessTy);
     if (TypeSize::isKnownLE(LoadSize, StoreSize))
       if (auto *C = dyn_cast<Constant>(Val))
         return ConstantFoldLoadFromConst(C, AccessTy, DL);

diff  --git a/llvm/test/Transforms/InstCombine/load-store-forward.ll b/llvm/test/Transforms/InstCombine/load-store-forward.ll
index 618e67ed0c8ec..750eb51e405d1 100644
--- a/llvm/test/Transforms/InstCombine/load-store-forward.ll
+++ b/llvm/test/Transforms/InstCombine/load-store-forward.ll
@@ -293,7 +293,9 @@ entry:
 define i8 @load_i8_store_i1(i1* %a) {
 ; CHECK-LABEL: @load_i8_store_i1(
 ; CHECK-NEXT:    store i1 true, i1* [[A:%.*]], align 1
-; CHECK-NEXT:    ret i8 -1
+; CHECK-NEXT:    [[A_I8:%.*]] = bitcast i1* [[A]] to i8*
+; CHECK-NEXT:    [[V:%.*]] = load i8, i8* [[A_I8]], align 1
+; CHECK-NEXT:    ret i8 [[V]]
 ;
   store i1 true, i1* %a
   %a.i8 = bitcast i1* %a to i8*


        


More information about the llvm-commits mailing list