[llvm] 762ac72 - [DAGCombiner] Fix DAG combine store elimination, different address space.

Hendrik Greving via llvm-commits llvm-commits at lists.llvm.org
Wed May 12 07:22:17 PDT 2021


Author: Hendrik Greving
Date: 2021-05-12T07:14:22-07:00
New Revision: 762ac725bf9775536dda5b3dda13574f14a8c2b9

URL: https://github.com/llvm/llvm-project/commit/762ac725bf9775536dda5b3dda13574f14a8c2b9
DIFF: https://github.com/llvm/llvm-project/commit/762ac725bf9775536dda5b3dda13574f14a8c2b9.diff

LOG: [DAGCombiner] Fix DAG combine store elimination, different address space.

Fixes a bug in the DAG combiner that eliminates the stores because it missed
to inspect the address space of the pointers.

%v = load %ptr_as1
// no chain side effect
store %v, %ptr_as2

As well as

store %v, %ptr_as1
store %v, %ptr_as2

Fixes a test for above in X86.

Differential Revision: https://reviews.llvm.org/D102096

Added: 
    

Modified: 
    llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
    llvm/test/CodeGen/X86/dagcombine-dead-store.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 26bbeb2bbb9c2..a12855c89c49c 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -17916,6 +17916,7 @@ SDValue DAGCombiner::visitSTORE(SDNode *N) {
   if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Value)) {
     if (Ld->getBasePtr() == Ptr && ST->getMemoryVT() == Ld->getMemoryVT() &&
         ST->isUnindexed() && ST->isSimple() &&
+        Ld->getAddressSpace() == ST->getAddressSpace() &&
         // There can't be any side effects between the load and store, such as
         // a call or store.
         Chain.reachesChainWithoutSideEffects(SDValue(Ld, 1))) {
@@ -17929,7 +17930,8 @@ SDValue DAGCombiner::visitSTORE(SDNode *N) {
     if (ST->isUnindexed() && ST->isSimple() &&
         ST1->isUnindexed() && ST1->isSimple()) {
       if (ST1->getBasePtr() == Ptr && ST1->getValue() == Value &&
-          ST->getMemoryVT() == ST1->getMemoryVT()) {
+          ST->getMemoryVT() == ST1->getMemoryVT() &&
+          ST->getAddressSpace() == ST1->getAddressSpace()) {
         // If this is a store followed by a store with the same value to the
         // same location, then the store is dead/noop.
         return Chain;
@@ -17940,7 +17942,8 @@ SDValue DAGCombiner::visitSTORE(SDNode *N) {
           // BaseIndexOffset and the code below requires knowing the size
           // of a vector, so bail out if MemoryVT is scalable.
           !ST->getMemoryVT().isScalableVector() &&
-          !ST1->getMemoryVT().isScalableVector()) {
+          !ST1->getMemoryVT().isScalableVector() &&
+          ST->getAddressSpace() == ST1->getAddressSpace()) {
         const BaseIndexOffset STBase = BaseIndexOffset::match(ST, DAG);
         const BaseIndexOffset ChainBase = BaseIndexOffset::match(ST1, DAG);
         unsigned STBitSize = ST->getMemoryVT().getFixedSizeInBits();

diff  --git a/llvm/test/CodeGen/X86/dagcombine-dead-store.ll b/llvm/test/CodeGen/X86/dagcombine-dead-store.ll
index 7b4970b0dd4d4..ca228d8923b35 100644
--- a/llvm/test/CodeGen/X86/dagcombine-dead-store.ll
+++ b/llvm/test/CodeGen/X86/dagcombine-dead-store.ll
@@ -6,12 +6,11 @@
 ; The test's 'same' and '
diff ' notation depicts whether the pointer value is the same
 ; or 
diff erent.
 
-; FIXME: DAG combine incorrectly eliminates store if pointer is of same value.
-
 define i32 @copy_fs_same() {
 ; CHECK-LABEL: copy_fs_same:
 ; CHECK:       # %bb.0: # %entry
 ; CHECK-NEXT:    movl 1, %eax
+; CHECK-NEXT:    movl %eax, %fs:1
 ; CHECK-NEXT:    retl
 entry:
    %0 = load i32, i32* inttoptr (i64 1 to i32*), align 4
@@ -36,6 +35,7 @@ define void @output_fs_same(i32 %v) {
 ; CHECK:       # %bb.0: # %entry
 ; CHECK-NEXT:    movl {{[0-9]+}}(%esp), %eax
 ; CHECK-NEXT:    movl %eax, 1
+; CHECK-NEXT:    movl %eax, %fs:1
 ; CHECK-NEXT:    retl
 entry:
   store i32 %v, i32* inttoptr (i64 1 to i32*), align 4
@@ -62,6 +62,7 @@ define void @output_indexed_fs_same(i32 %v, i32* %b) {
 ; CHECK-NEXT:    movl {{[0-9]+}}(%esp), %eax
 ; CHECK-NEXT:    movl {{[0-9]+}}(%esp), %ecx
 ; CHECK-NEXT:    movl %eax, 168(%ecx)
+; CHECK-NEXT:    movl %eax, %fs:168(%ecx)
 ; CHECK-NEXT:    retl
   %p = getelementptr i32, i32* %b, i64 42
   %pa = addrspacecast i32* %p to i32 addrspace(257)*


        


More information about the llvm-commits mailing list