[PATCH] D158366: [DAG] replaceStoreOfInsertLoad - don't fold if the inserted element is implicity truncated

Simon Pilgrim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 20 07:49:15 PDT 2023


RKSimon created this revision.
RKSimon added reviewers: jacobly, craig.topper, foad, luke, pengfei.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
RKSimon requested review of this revision.
Herald added a project: LLVM.

D152276 <https://reviews.llvm.org/D152276> wasn't handling the case where the inserted element is implicity truncated into the vector - resulting in a i1 element (implictly truncated from i8) overwriting 8 bits instead of 1 bit.

This patch is intended to be merged into 17.x so I've just disallowed any vector element vs inserted element type mismatch - technically we could be more elegant and permit truncated stores (as long as the store is still byte sized), but the use cases for that are so limited I'd prefer to play it safe for now.

Candidate patch for #64655 17.x merge


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158366

Files:
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/test/CodeGen/X86/pr64655.ll


Index: llvm/test/CodeGen/X86/pr64655.ll
===================================================================
--- llvm/test/CodeGen/X86/pr64655.ll
+++ llvm/test/CodeGen/X86/pr64655.ll
@@ -41,7 +41,16 @@
 ;
 ; AVX512-LABEL: f:
 ; AVX512:       # %bb.0:
-; AVX512-NEXT:    movb $1, 1(%rdi)
+; AVX512-NEXT:    kmovb (%rdi), %k0
+; AVX512-NEXT:    movb $-3, %al
+; AVX512-NEXT:    kmovd %eax, %k1
+; AVX512-NEXT:    kandb %k1, %k0, %k0
+; AVX512-NEXT:    movb $1, %al
+; AVX512-NEXT:    kmovd %eax, %k1
+; AVX512-NEXT:    kshiftlb $7, %k1, %k1
+; AVX512-NEXT:    kshiftrb $6, %k1, %k1
+; AVX512-NEXT:    korb %k1, %k0, %k0
+; AVX512-NEXT:    kmovb %k0, (%rdi)
 ; AVX512-NEXT:    retq
   %2 = load <8 x i1>, ptr %0
   %3 = insertelement <8 x i1> %2, i1 true, i32 1
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -20508,9 +20508,10 @@
   SDValue Elt = Value.getOperand(1);
   SDValue Idx = Value.getOperand(2);
 
-  // If the element isn't byte sized then we can't compute an offset
+  // If the element isn't byte sized or is implicitly truncated then we can't
+  // compute an offset.
   EVT EltVT = Elt.getValueType();
-  if (!EltVT.isByteSized())
+  if (!EltVT.isByteSized() || EltVT != Value.getOperand(0).getValueType())
     return SDValue();
 
   auto *Ld = dyn_cast<LoadSDNode>(Value.getOperand(0));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158366.551837.patch
Type: text/x-patch
Size: 1478 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230820/d2dd079d/attachment.bin>


More information about the llvm-commits mailing list