Skip to content

Commit 8f611d6

Browse files
jrtc27resistor
authored andcommitted
[CodeGen] Use index type for pointer offset in replaceStoreOfInsertLoad
Also use getMemBasePlusOffset rather than a raw ADD since that won't work for capability types either. Fixes: 38e1851 ("[DAGCombine] Fold (store (insert_elt (load p)) x p) -> (store x)")
1 parent 6b04278 commit 8f611d6

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; RUN: llc @PURECAP_HARDFLOAT_ARGS@ -O0 < %s | FileCheck %s
2+
3+
;; Test that, when DAGCombiner folds a load-insert-store to just storing the
4+
;; element, it uses the index rather than pointer type for the offset. Without
5+
;; this it would crash with:
6+
;;
7+
;; Assertion `Int.isZero() && "Should not create non-zero capability " "constants with SelectionDAG::getConstant()"' failed.
8+
define void @foo(ptr addrspace(200) %p) addrspace(200) {
9+
entry:
10+
%0 = load <4 x i8>, ptr addrspace(200) %p, align 4
11+
%1 = insertelement <4 x i8> %0, i8 0, i64 0
12+
store <4 x i8> %1, ptr addrspace(200) %p, align 4
13+
ret void
14+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --scrub-attributes --version 2
2+
; DO NOT EDIT -- This file was generated from test/CodeGen/CHERI-Generic/Inputs/store-insert-load-index-type.ll
3+
; RUN: llc -mtriple=mips64 -mcpu=cheri128 -mattr=+cheri128 --relocation-model=pic -target-abi purecap -O0 < %s | FileCheck %s
4+
5+
;; Test that, when DAGCombiner folds a load-insert-store to just storing the
6+
;; element, it uses the index rather than pointer type for the offset. Without
7+
;; this it would crash with:
8+
;;
9+
;; Assertion `Int.isZero() && "Should not create non-zero capability " "constants with SelectionDAG::getConstant()"' failed.
10+
define void @foo(ptr addrspace(200) %p) addrspace(200) {
11+
; CHECK-LABEL: foo:
12+
; CHECK: # %bb.0: # %entry
13+
; CHECK-NEXT: daddiu $1, $zero, 0
14+
; CHECK-NEXT: csb $zero, $zero, 0($c3)
15+
; CHECK-NEXT: cjr $c17
16+
; CHECK-NEXT: nop
17+
entry:
18+
%0 = load <4 x i8>, ptr addrspace(200) %p, align 4
19+
%1 = insertelement <4 x i8> %0, i8 0, i64 0
20+
store <4 x i8> %1, ptr addrspace(200) %p, align 4
21+
ret void
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; DO NOT EDIT -- This file was generated from test/CodeGen/CHERI-Generic/Inputs/store-insert-load-index-type.ll
3+
; RUN: llc -mtriple=riscv32 --relocation-model=pic -target-abi il32pc64f -mattr=+xcheri,+xcheripurecap,+f -O0 < %s | FileCheck %s
4+
5+
;; Test that, when DAGCombiner folds a load-insert-store to just storing the
6+
;; element, it uses the index rather than pointer type for the offset. Without
7+
;; this it would crash with:
8+
;;
9+
;; Assertion `Int.isZero() && "Should not create non-zero capability " "constants with SelectionDAG::getConstant()"' failed.
10+
define void @foo(ptr addrspace(200) %p) addrspace(200) {
11+
; CHECK-LABEL: foo:
12+
; CHECK: # %bb.0: # %entry
13+
; CHECK-NEXT: cmove a1, a0
14+
; CHECK-NEXT: li a0, 0
15+
; CHECK-NEXT: csb a0, 0(a1)
16+
; CHECK-NEXT: cret
17+
entry:
18+
%0 = load <4 x i8>, ptr addrspace(200) %p, align 4
19+
%1 = insertelement <4 x i8> %0, i8 0, i64 0
20+
store <4 x i8> %1, ptr addrspace(200) %p, align 4
21+
ret void
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; DO NOT EDIT -- This file was generated from test/CodeGen/CHERI-Generic/Inputs/store-insert-load-index-type.ll
3+
; RUN: llc -mtriple=riscv64 --relocation-model=pic -target-abi l64pc128d -mattr=+xcheri,+xcheripurecap,+f,+d -O0 < %s | FileCheck %s
4+
5+
;; Test that, when DAGCombiner folds a load-insert-store to just storing the
6+
;; element, it uses the index rather than pointer type for the offset. Without
7+
;; this it would crash with:
8+
;;
9+
;; Assertion `Int.isZero() && "Should not create non-zero capability " "constants with SelectionDAG::getConstant()"' failed.
10+
define void @foo(ptr addrspace(200) %p) addrspace(200) {
11+
; CHECK-LABEL: foo:
12+
; CHECK: # %bb.0: # %entry
13+
; CHECK-NEXT: cmove a1, a0
14+
; CHECK-NEXT: li a0, 0
15+
; CHECK-NEXT: csb a0, 0(a1)
16+
; CHECK-NEXT: cret
17+
entry:
18+
%0 = load <4 x i8>, ptr addrspace(200) %p, align 4
19+
%1 = insertelement <4 x i8> %0, i8 0, i64 0
20+
store <4 x i8> %1, ptr addrspace(200) %p, align 4
21+
ret void
22+
}

0 commit comments

Comments
 (0)