<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/62828>62828</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [TBAA][DSE] The incorrect analysis result of TBAA led to the erroneous deletion of store instructions.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          hlyix
      </td>
    </tr>
</table>

<pre>
    RSIC-V and AMDGPU could Reproduce this issue

`clang --target=riscv64 -march=rv64gc  test.cpp  -O2 -emit-obj -mllvm -print-after-all -mllvm -indvars-widen-indvars=false -mllvm -dse-memoryssa-walklimit=10000 -mllvm -dse-memoryssa-scanlimit=10000 -S -emit-llvm -o a.s &> riscv_print.log`

`clang --target=amdgcn -march=rv64gc  test.cpp  -O2 -emit-obj -mllvm -print-after-all -mllvm -indvars-widen-indvars=false -mllvm -dse-memoryssa-walklimit=10000 -mllvm -dse-memoryssa-scanlimit=10000 -S -emit-llvm -o a.s &> amd_print.log`

Here is test.cpp
```cpp
typedef int half32;
typedef half32 half32_v8[8];
typedef short half;
typedef half half_v8[8];
half* test(int* ptr) {
  half32_v8 cast_c_array[4];
  half_v8 shuf_c_array1[4];
  half32* input1 = reinterpret_cast<half32*>(((half32_v8*)(cast_c_array)));
  half* input2 = reinterpret_cast<half*>(reinterpret_cast<half32_v8*>(input1));
  half* output1 = reinterpret_cast<half*>(((half_v8*)(shuf_c_array1)));
  half* output2 = reinterpret_cast<half*>(reinterpret_cast<half_v8*>(output1));
 for (int r = 0; r < 8; ++r) {
    half32 tmp = (half32)((r * 4) + ptr[r]);
    if ((ptr[r] / 4) == 0) {
      half32* input = reinterpret_cast<half32*>(((half32_v8*)(cast_c_array)));
      input[r] = tmp;
    }
  }
  for (int i3 = 0; i3 < 32; ++i3) {
 output2[i3] = input2[(i3 * 2)];
  }
  return output2;
}
```

Here is log before and after DSE in rsicv arch, we could see that store instructions deleted in if.then.0 ~ if.then.7 which should not delete.
**before dse**
```
*** IR Dump After MemCpyOptPass on _Z4testPi ***
; Function Attrs: mustprogress nounwind
define dso_local noundef ptr @_Z4testPi(ptr noundef %ptr) local_unnamed_addr #0 {
entry:
  %cast_c_array = alloca [4 x [8 x i32]], align 4
  %shuf_c_array1 = alloca [4 x [8 x i16]], align 2
 call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %cast_c_array) #2
 call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %shuf_c_array1) #2
 %0 = load i32, ptr %ptr, align 4, !tbaa !4
  %.off = add i32 %0, 3
 %cmp4 = icmp ult i32 %.off, 7
  br i1 %cmp4, label %if.then, label %if.end

if.then:                                          ; preds = %entry
  store i32 %0, ptr %cast_c_array, align 4, !tbaa !4
  br label %if.end

if.end:                                           ; preds = %if.then, %entry
  %arrayidx.1 = getelementptr inbounds i32, ptr %ptr, i64 1
  %1 = load i32, ptr %arrayidx.1, align 4, !tbaa !4
  %.off.1 = add i32 %1, 3
  %cmp4.1 = icmp ult i32 %.off.1, 7
  br i1 %cmp4.1, label %if.then.1, label %if.end.1

if.then.1: ; preds = %if.end
  %add.1 = add nsw i32 %1, 4
  %arrayidx7.1 = getelementptr inbounds i32, ptr %cast_c_array, i64 1
  store i32 %add.1, ptr %arrayidx7.1, align 4, !tbaa !4
  br label %if.end.1

if.end.1: ; preds = %if.then.1, %if.end
 %arrayidx.2 = getelementptr inbounds i32, ptr %ptr, i64 2
  %2 = load i32, ptr %arrayidx.2, align 4, !tbaa !4
  %.off.2 = add i32 %2, 3
  %cmp4.2 = icmp ult i32 %.off.2, 7
  br i1 %cmp4.2, label %if.then.2, label %if.end.2

if.then.2:                                        ; preds = %if.end.1
  %add.2 = add nsw i32 %2, 8
  %arrayidx7.2 = getelementptr inbounds i32, ptr %cast_c_array, i64 2
  store i32 %add.2, ptr %arrayidx7.2, align 4, !tbaa !4
  br label %if.end.2

if.end.2: ; preds = %if.then.2, %if.end.1
 %arrayidx.3 = getelementptr inbounds i32, ptr %ptr, i64 3
  %3 = load i32, ptr %arrayidx.3, align 4, !tbaa !4
  %.off.3 = add i32 %3, 3
  %cmp4.3 = icmp ult i32 %.off.3, 7
  br i1 %cmp4.3, label %if.then.3, label %if.end.3

if.then.3:                                        ; preds = %if.end.2
  %add.3 = add nsw i32 %3, 12
  %arrayidx7.3 = getelementptr inbounds i32, ptr %cast_c_array, i64 3
  store i32 %add.3, ptr %arrayidx7.3, align 4, !tbaa !4
  br label %if.end.3

if.end.3: ; preds = %if.then.3, %if.end.2
 %arrayidx.4 = getelementptr inbounds i32, ptr %ptr, i64 4
  %4 = load i32, ptr %arrayidx.4, align 4, !tbaa !4
  %.off.4 = add i32 %4, 3
  %cmp4.4 = icmp ult i32 %.off.4, 7
  br i1 %cmp4.4, label %if.then.4, label %if.end.4

if.then.4:                                        ; preds = %if.end.3
  %add.4 = add nsw i32 %4, 16
  %arrayidx7.4 = getelementptr inbounds i32, ptr %cast_c_array, i64 4
  store i32 %add.4, ptr %arrayidx7.4, align 4, !tbaa !4
  br label %if.end.4

if.end.4: ; preds = %if.then.4, %if.end.3
 %arrayidx.5 = getelementptr inbounds i32, ptr %ptr, i64 5
  %5 = load i32, ptr %arrayidx.5, align 4, !tbaa !4
  %.off.5 = add i32 %5, 3
  %cmp4.5 = icmp ult i32 %.off.5, 7
  br i1 %cmp4.5, label %if.then.5, label %if.end.5

if.then.5:                                        ; preds = %if.end.4
  %add.5 = add nsw i32 %5, 20
  %arrayidx7.5 = getelementptr inbounds i32, ptr %cast_c_array, i64 5
  store i32 %add.5, ptr %arrayidx7.5, align 4, !tbaa !4
  br label %if.end.5

if.end.5: ; preds = %if.then.5, %if.end.4
 %arrayidx.6 = getelementptr inbounds i32, ptr %ptr, i64 6
  %6 = load i32, ptr %arrayidx.6, align 4, !tbaa !4
  %.off.6 = add i32 %6, 3
  %cmp4.6 = icmp ult i32 %.off.6, 7
  br i1 %cmp4.6, label %if.then.6, label %if.end.6

if.then.6:                                        ; preds = %if.end.5
  %add.6 = add nsw i32 %6, 24
  %arrayidx7.6 = getelementptr inbounds i32, ptr %cast_c_array, i64 6
  store i32 %add.6, ptr %arrayidx7.6, align 4, !tbaa !4
  br label %if.end.6

if.end.6: ; preds = %if.then.6, %if.end.5
 %arrayidx.7 = getelementptr inbounds i32, ptr %ptr, i64 7
  %7 = load i32, ptr %arrayidx.7, align 4, !tbaa !4
  %.off.7 = add i32 %7, 3
  %cmp4.7 = icmp ult i32 %.off.7, 7
  br i1 %cmp4.7, label %if.then.7, label %if.end.7

if.then.7:                                        ; preds = %if.end.6
  %add.7 = add nsw i32 %7, 28
  %arrayidx7.7 = getelementptr inbounds i32, ptr %cast_c_array, i64 7
  store i32 %add.7, ptr %arrayidx7.7, align 4, !tbaa !4
  br label %if.end.7

if.end.7: ; preds = %if.then.7, %if.end.6
  br label %for.body11

for.cond.cleanup10:                               ; preds = %for.body11
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %shuf_c_array1) #2
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %cast_c_array) #2
  ret ptr %shuf_c_array1

for.body11: ; preds = %if.end.7, %for.body11
  %i3.031 = phi i32 [ %inc18, %for.body11 ], [ 0, %if.end.7 ]
  %mul12 = shl nuw nsw i32 %i3.031, 1
  %idxprom13 = zext i32 %mul12 to i64
  %arrayidx14 = getelementptr inbounds i16, ptr %cast_c_array, i64 %idxprom13
  %8 = load i16, ptr %arrayidx14, align 4, !tbaa !8
  %idxprom15 = zext i32 %i3.031 to i64
  %arrayidx16 = getelementptr inbounds i16, ptr %shuf_c_array1, i64 %idxprom15
  store i16 %8, ptr %arrayidx16, align 2, !tbaa !8
  %inc18 = add nuw nsw i32 %i3.031, 1
  %exitcond.not = icmp eq i32 %inc18, 32
 br i1 %exitcond.not, label %for.cond.cleanup10, label %for.body11, !llvm.loop !10
}

```
**after dse**
```
*** IR Dump After DSEPass on _Z4testPi ***
; Function Attrs: mustprogress nounwind
define dso_local noundef ptr @_Z4testPi(ptr noundef %ptr) local_unnamed_addr #0 {
entry:
  %cast_c_array = alloca [4 x [8 x i32]], align 4
 %shuf_c_array1 = alloca [4 x [8 x i16]], align 2
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %cast_c_array) #2
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %shuf_c_array1) #2
  %0 = load i32, ptr %ptr, align 4, !tbaa !4
  %.off = add i32 %0, 3
  %cmp4 = icmp ult i32 %.off, 7
  br i1 %cmp4, label %if.then, label %if.end

if.then:                                          ; preds = %entry
  br label %if.end

if.end: ; preds = %if.then, %entry
  %arrayidx.1 = getelementptr inbounds i32, ptr %ptr, i64 1
  %1 = load i32, ptr %arrayidx.1, align 4, !tbaa !4
  %.off.1 = add i32 %1, 3
  %cmp4.1 = icmp ult i32 %.off.1, 7
 br i1 %cmp4.1, label %if.then.1, label %if.end.1

if.then.1: ; preds = %if.end
  br label %if.end.1

if.end.1:                                         ; preds = %if.then.1, %if.end
  %arrayidx.2 = getelementptr inbounds i32, ptr %ptr, i64 2
  %2 = load i32, ptr %arrayidx.2, align 4, !tbaa !4
  %.off.2 = add i32 %2, 3
  %cmp4.2 = icmp ult i32 %.off.2, 7
  br i1 %cmp4.2, label %if.then.2, label %if.end.2

if.then.2: ; preds = %if.end.1
  br label %if.end.2

if.end.2: ; preds = %if.then.2, %if.end.1
 %arrayidx.3 = getelementptr inbounds i32, ptr %ptr, i64 3
  %3 = load i32, ptr %arrayidx.3, align 4, !tbaa !4
  %.off.3 = add i32 %3, 3
  %cmp4.3 = icmp ult i32 %.off.3, 7
  br i1 %cmp4.3, label %if.then.3, label %if.end.3

if.then.3:                                        ; preds = %if.end.2
  br label %if.end.3

if.end.3: ; preds = %if.then.3, %if.end.2
  %arrayidx.4 = getelementptr inbounds i32, ptr %ptr, i64 4
  %4 = load i32, ptr %arrayidx.4, align 4, !tbaa !4
  %.off.4 = add i32 %4, 3
  %cmp4.4 = icmp ult i32 %.off.4, 7
  br i1 %cmp4.4, label %if.then.4, label %if.end.4

if.then.4: ; preds = %if.end.3
  br label %if.end.4

if.end.4:                                         ; preds = %if.then.4, %if.end.3
  %arrayidx.5 = getelementptr inbounds i32, ptr %ptr, i64 5
  %5 = load i32, ptr %arrayidx.5, align 4, !tbaa !4
 %.off.5 = add i32 %5, 3
  %cmp4.5 = icmp ult i32 %.off.5, 7
  br i1 %cmp4.5, label %if.then.5, label %if.end.5

if.then.5: ; preds = %if.end.4
  br label %if.end.5

if.end.5:                                         ; preds = %if.then.5, %if.end.4
  %arrayidx.6 = getelementptr inbounds i32, ptr %ptr, i64 6
  %6 = load i32, ptr %arrayidx.6, align 4, !tbaa !4
 %.off.6 = add i32 %6, 3
  %cmp4.6 = icmp ult i32 %.off.6, 7
  br i1 %cmp4.6, label %if.then.6, label %if.end.6

if.then.6: ; preds = %if.end.5
  br label %if.end.6

if.end.6:                                         ; preds = %if.then.6, %if.end.5
  %arrayidx.7 = getelementptr inbounds i32, ptr %ptr, i64 7
  %7 = load i32, ptr %arrayidx.7, align 4, !tbaa !4
 %.off.7 = add i32 %7, 3
  %cmp4.7 = icmp ult i32 %.off.7, 7
  br i1 %cmp4.7, label %if.then.7, label %if.end.7

if.then.7: ; preds = %if.end.6
  br label %if.end.7

if.end.7:                                         ; preds = %if.then.7, %if.end.6
  br label %for.body11

for.cond.cleanup10: ; preds = %for.body11
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %shuf_c_array1) #2
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %cast_c_array) #2
  ret ptr %shuf_c_array1

for.body11:                                       ; preds = %if.end.7, %for.body11
  %i3.031 = phi i32 [ %inc18, %for.body11 ], [ 0, %if.end.7 ]
  %mul12 = shl nuw nsw i32 %i3.031, 1
  %idxprom13 = zext i32 %mul12 to i64
  %arrayidx14 = getelementptr inbounds i16, ptr %cast_c_array, i64 %idxprom13
  %8 = load i16, ptr %arrayidx14, align 4, !tbaa !8
  %idxprom15 = zext i32 %i3.031 to i64
  %arrayidx16 = getelementptr inbounds i16, ptr %shuf_c_array1, i64 %idxprom15
  store i16 %8, ptr %arrayidx16, align 2, !tbaa !8
  %inc18 = add nuw nsw i32 %i3.031, 1
  %exitcond.not = icmp eq i32 %inc18, 32
  br i1 %exitcond.not, label %for.cond.cleanup10, label %for.body11, !llvm.loop !10
}
```


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsm0tzqzgWgH-NsjllF0g8nEUWdnwz04uu7urbM4vZpDDItnpAMJLIYxbz26ckYQxY2CbJ7bq3KymXH0I6Oo9PEjmnSKRkO07pHQpXKFzfJLXal-Jun7-yl5tNmb3e_fb1p_vZPyHhGSx_Xv_t139AWtZ5Br_RSpRZnVJQeyaBSVlT5K2Rt2zeIy_NE76D2UwlYkcVImvBZPoUBTArEpHudcNTFOxSAEWlmqdVBTD7BcOMFkzNys0fMCvy_KmAWSUYV7Nkq6iYJXnetjOePSVCzp5ZRvnhFyLrbZJL2vbKJJ0VtCjFq5TJ7DnJ_52zgmmFfM_zvJF-Mk34oN_XRjXbvYRkLgHhCJEvYEx7NHrO83KHIu-SM5Ii26X8r-iLpMhGPfF3Kigw2VrZ-se-2hb1WtGMboFxBfsk3xKMyKp_yTY3H49PCxSuFihcn_ST-1JYIU4R5s0x3AzAS6MpwgvGlf5VKYHwLaC46QXH-SFNpHpMHxMhklcUroKuNDhMA3Jfbw-9fHc3gvVUjFe18gGRNQjKuKKiElQ96lkQuW_7IfIF4YV9HX2BlwjfIrzo6aRbzKs_XTsZPjdZO9WoMs28ppNVfnS6slaXjHOY1jWs78Yzltmp3mVa17BG8-F021KApQSEmcpDZGW-3sNCf0V4hfBqCM8h3qCKygxrg2it1DqBtiIwA_HKABiuhIamZy4A24IdcewCCD80Q8naajWc_4S4bwyc0VTP06pI1tr6XhcUrw8_Ol87Pmbk6GTz_R7MDtG4mZG-nQ0DKNRXmjkt8frcwwstAi_BOL23GjuzC6pqwV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