[llvm] 3563af6 - [DAGCombiner] In mergeTruncStore, make sure we aren't storing shifted in bits. (#90939)

via llvm-commits llvm-commits at lists.llvm.org
Fri May 3 09:59:36 PDT 2024


Author: Craig Topper
Date: 2024-05-03T09:59:33-07:00
New Revision: 3563af6c06ebc92bcaacef0e33285148ef0f75bd

URL: https://github.com/llvm/llvm-project/commit/3563af6c06ebc92bcaacef0e33285148ef0f75bd
DIFF: https://github.com/llvm/llvm-project/commit/3563af6c06ebc92bcaacef0e33285148ef0f75bd.diff

LOG: [DAGCombiner] In mergeTruncStore, make sure we aren't storing shifted in bits. (#90939)

When looking through a right shift, we need to make sure that all of
the bits we are using from the shift come from the shift input and
not the sign or zero bits that are shifted in.
    
Fixes #90936.

Added: 
    

Modified: 
    llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
    llvm/test/CodeGen/AArch64/pr90936.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index c0bbea16a64262..fc6bbc119d3c1b 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -8840,6 +8840,10 @@ SDValue DAGCombiner::mergeTruncStores(StoreSDNode *N) {
       if (ShiftAmtC % NarrowNumBits != 0)
         return SDValue();
 
+      // Make sure we aren't reading bits that are shifted in.
+      if (ShiftAmtC > WideVal.getScalarValueSizeInBits() - NarrowNumBits)
+        return SDValue();
+
       Offset = ShiftAmtC / NarrowNumBits;
       WideVal = WideVal.getOperand(0);
     }

diff  --git a/llvm/test/CodeGen/AArch64/pr90936.ll b/llvm/test/CodeGen/AArch64/pr90936.ll
index 62c18fa5218765..38cda8d388945f 100644
--- a/llvm/test/CodeGen/AArch64/pr90936.ll
+++ b/llvm/test/CodeGen/AArch64/pr90936.ll
@@ -3,8 +3,10 @@
 
 define void @f(i16 %arg, ptr %arg1) {
 ; CHECK-LABEL: f:
-; CHECK:       // %bb.0: // %bb
-; CHECK-NEXT:    strh w0, [x1]
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    ubfx w8, w0, #8, #6
+; CHECK-NEXT:    strb w0, [x1]
+; CHECK-NEXT:    strb w8, [x1, #1]
 ; CHECK-NEXT:    ret
 bb:
   %i = trunc i16 %arg to i8


        


More information about the llvm-commits mailing list