[llvm] ac9e959 - [AArch64] Add shrink-wrapping test with missing memoperands.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri May 12 07:38:47 PDT 2023
Author: Florian Hahn
Date: 2023-05-12T15:38:31+01:00
New Revision: ac9e9594af373f5273c61af7534cc8bdb6eae084
URL: https://github.com/llvm/llvm-project/commit/ac9e9594af373f5273c61af7534cc8bdb6eae084
DIFF: https://github.com/llvm/llvm-project/commit/ac9e9594af373f5273c61af7534cc8bdb6eae084.diff
LOG: [AArch64] Add shrink-wrapping test with missing memoperands.
The newly added compiler_pop_stack_no_memoperands has no memory operands
on the memory instructions but accesses the same locations as
compiler_pop_stack. At the moment, accesses to the stack are missed by
shrink-wrapping. Test case for the issue pointed out by @jpenix-quic in
D149668 post-commit.
Added:
Modified:
llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir
Removed:
################################################################################
diff --git a/llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir b/llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir
index bc60b7b57119..eeede52e8d26 100644
--- a/llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir
+++ b/llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir
@@ -5,12 +5,16 @@
; RUN: llc -x=mir -simplify-mir -run-pass=shrink-wrap -o - %s | FileCheck %s
; CHECK: name: compiler_pop_stack
- ; CHECK: frameInfo:
+ ; CHECK: frameInfo:
; CHECK-NOT: savePoint:
; CHECK-NOT: restorePoint:
+ ; CHECK: name: compiler_pop_stack_no_memoperands
+ ; CHECK: frameInfo:
+ ; CHECK: savePoint:
+ ; CHECK: restorePoint:
; CHECK: stack:
; CHECK: name: f
- ; CHECK: frameInfo:
+ ; CHECK: frameInfo:
; CHECK: savePoint: '%bb.2'
; CHECK-NEXT: restorePoint: '%bb.4'
; CHECK-NEXT: stack:
@@ -20,99 +24,38 @@
%struct.S = type { i32, i32 }
- @__const.f.arr = private unnamed_addr constant [4 x i8] c"\01\02\03\04", align 1
-
-
- declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture)
-
-
- declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture)
-
-
- declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1 immarg)
; Test from: https://bugs.llvm.org/show_bug.cgi?id=42136
- define void @compiler_pop_stack(i32 %num) {
+ define void @compiler_pop_stack(i32 %num, i32 %dec) {
entry:
%rstack = alloca [16 x i32], align 4
- %tmp = bitcast [16 x i32]* %rstack to i8*
- call void @llvm.lifetime.start.p0i8(i64 64, i8* nonnull %tmp)
- %cmp = icmp ult i32 %num, 2
- br i1 %cmp, label %cleanup, label %if.end
-
- if.end:
- %arrayidx1 = bitcast [16 x i32]* %rstack to i32*
- store volatile i32 %num, i32* %arrayidx1, align 4
- br label %while.body
-
- while.body:
- %ptr.017 = phi i32 [ 1, %if.end ], [ %ptr.1, %if.end7 ]
- %dec = add i32 %ptr.017, -1
%idxprom = zext i32 %dec to i64
- %arrayidx2 = getelementptr inbounds [16 x i32], [16 x i32]* %rstack, i64 0, i64 %idxprom
- %tmp1 = load volatile i32, i32* %arrayidx2, align 4
- %cmp3 = icmp eq i32 %tmp1, 0
- br i1 %cmp3, label %if.end7, label %if.then4
+ %arrayidx2 = getelementptr inbounds [16 x i32], ptr %rstack, i64 0, i64 %idxprom
+ %sunkaddr = mul i64 %idxprom, 4
+ %sunkaddr2 = getelementptr inbounds i8, ptr %rstack, i64 %sunkaddr
+ ret void
+ }
- if.then4:
+ define void @compiler_pop_stack_no_memoperands(i32 %num, i32 %dec) {
+ entry:
+ %rstack = alloca [16 x i32], align 4
+ %idxprom = zext i32 %dec to i64
+ %arrayidx2 = getelementptr inbounds [16 x i32], ptr %rstack, i64 0, i64 %idxprom
%sunkaddr = mul i64 %idxprom, 4
- %0 = bitcast [16 x i32]* %rstack to i8*
- %sunkaddr2 = getelementptr inbounds i8, i8* %0, i64 %sunkaddr
- %1 = bitcast i8* %sunkaddr2 to i32*
- store volatile i32 %tmp1, i32* %1, align 4
- br label %if.end7
-
- if.end7:
- %ptr.1 = phi i32 [ %ptr.017, %if.then4 ], [ %dec, %while.body ]
- %cmp1 = icmp eq i32 %ptr.1, 0
- br i1 %cmp1, label %cleanup, label %while.body
-
- cleanup:
- %2 = bitcast [16 x i32]* %rstack to i8*
- call void @llvm.lifetime.end.p0i8(i64 64, i8* nonnull %2)
+ %sunkaddr2 = getelementptr inbounds i8, ptr %rstack, i64 %sunkaddr
ret void
}
+
+
; Test from: https://bugs.llvm.org/show_bug.cgi?id=37472
define i32 @f(%struct.S* nocapture %arg, i32 %arg1) {
bb:
%tmp = alloca [4 x i8], align 1
- %tmp2 = icmp ugt i32 %arg1, 4
- br i1 %tmp2, label %bb16, label %bb3
-
- bb3:
- %tmp41 = bitcast [4 x i8]* %tmp to i8*
- call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %tmp41)
- call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 1 %tmp41, i8* align 1 getelementptr inbounds ([4 x i8], [4 x i8]* @__const.f.arr, i64 0, i64 0), i64 4, i1 true)
- %tmp5 = zext i32 %arg1 to i64
- %tmp6 = getelementptr inbounds [4 x i8], [4 x i8]* %tmp, i64 0, i64 %tmp5
- %tmp7 = load volatile i8, i8* %tmp6, align 1
- %tmp8 = zext i8 %tmp7 to i32
- %tmp92 = bitcast %struct.S* %arg to i32*
- store i32 %tmp8, i32* %tmp92, align 4
- %tmp10 = icmp ult i32 %arg1, 3
- br i1 %tmp10, label %bb11, label %bb15
-
- bb11:
- %0 = bitcast [4 x i8]* %tmp to i8*
- %sunkaddr = getelementptr inbounds i8, i8* %0, i64 %tmp5
- %tmp12 = load volatile i8, i8* %sunkaddr, align 1
- %tmp13 = zext i8 %tmp12 to i32
- %tmp14 = getelementptr inbounds %struct.S, %struct.S* %arg, i64 0, i32 1
- store i32 %tmp13, i32* %tmp14, align 4
- br label %bb15
-
- bb15:
- %1 = bitcast [4 x i8]* %tmp to i8*
- call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %1)
- br label %bb16
-
- bb16:
- %tmp17 = phi i32 [ 0, %bb15 ], [ 1, %bb ]
- ret i32 %tmp17
+ %tmp6 = getelementptr inbounds [4 x i8], ptr %tmp, i64 0, i64 3
+ %sunkaddr = getelementptr inbounds i8, ptr %tmp, i64 3
+ %tmp14 = getelementptr inbounds %struct.S, ptr %arg, i64 0, i32 1
+ ret i32 0
}
-
- declare void @llvm.stackprotector(i8*, i8**)
-
...
---
name: compiler_pop_stack
@@ -128,21 +71,21 @@ stack:
- { id: 0, name: rstack, size: 64, alignment: 4, stack-id: default, local-offset: -64 }
machineFunctionInfo: {}
body: |
- bb.0.entry:
+ bb.0:
liveins: $w0
dead $wzr = SUBSWri renamable $w0, 2, 0, implicit-def $nzcv
Bcc 3, %bb.6, implicit killed $nzcv
B %bb.1
- bb.1.if.end:
+ bb.1:
liveins: $w0
- STRWui killed renamable $w0, %stack.0.rstack, 0 :: (volatile store (s32) into %ir.arrayidx1)
+ STRWui killed renamable $w0, %stack.0.rstack, 0 :: (volatile store (s32) into %ir.rstack)
renamable $w9 = MOVi32imm 1
renamable $x8 = ADDXri %stack.0.rstack, 0, 0
- bb.2.while.body:
+ bb.2:
successors: %bb.3(0x30000000), %bb.4(0x50000000)
liveins: $w9, $x8
@@ -156,22 +99,81 @@ body: |
renamable $w9 = COPY renamable $w10, implicit killed $x10
B %bb.5
- bb.4.if.then4:
+ bb.4:
+ liveins: $w9, $w11, $x8, $x10
+
+ STRWroX killed renamable $w11, renamable $x8, killed renamable $x10, 0, 1 :: (volatile store (s32) into %ir.sunkaddr2)
+
+ bb.5:
+ successors: %bb.6(0x04000000), %bb.2(0x7c000000)
+ liveins: $w9, $x8
+
+ CBNZW renamable $w9, %bb.2
+ B %bb.6
+
+ bb.6:
+ RET_ReallyLR
+
+...
+---
+name: compiler_pop_stack_no_memoperands
+alignment: 4
+tracksRegLiveness: true
+liveins:
+ - { reg: '$w0' }
+frameInfo:
+ maxAlignment: 4
+ maxCallFrameSize: 0
+ localFrameSize: 64
+stack:
+ - { id: 0, name: rstack, size: 64, alignment: 4, stack-id: default, local-offset: -64 }
+machineFunctionInfo: {}
+body: |
+ bb.0:
+ liveins: $w0
+
+ dead $wzr = SUBSWri renamable $w0, 2, 0, implicit-def $nzcv
+ Bcc 3, %bb.6, implicit killed $nzcv
+ B %bb.1
+
+ bb.1:
+ liveins: $w0
+
+ STRWui killed renamable $w0, %stack.0.rstack, 0
+ renamable $w9 = MOVi32imm 1
+ renamable $x8 = ADDXri %stack.0.rstack, 0, 0
+
+ bb.2:
+ successors: %bb.3(0x30000000), %bb.4(0x50000000)
+ liveins: $w9, $x8
+
+ renamable $w10 = SUBWri renamable $w9, 1, 0, implicit-def $x10
+ renamable $w11 = LDRWroW renamable $x8, renamable $w10, 0, 1
+ CBNZW renamable $w11, %bb.4
+
+ bb.3:
+ liveins: $x8, $x10
+
+ renamable $w9 = COPY renamable $w10, implicit killed $x10
+ B %bb.5
+
+ bb.4:
liveins: $w9, $w11, $x8, $x10
- STRWroX killed renamable $w11, renamable $x8, killed renamable $x10, 0, 1 :: (volatile store (s32) into %ir.1)
+ STRWroX killed renamable $w11, renamable $x8, killed renamable $x10, 0, 1
- bb.5.if.end7:
+ bb.5:
successors: %bb.6(0x04000000), %bb.2(0x7c000000)
liveins: $w9, $x8
CBNZW renamable $w9, %bb.2
B %bb.6
- bb.6.cleanup:
+ bb.6:
RET_ReallyLR
...
+
---
name: f
alignment: 4
@@ -187,7 +189,7 @@ stack:
- { id: 0, name: tmp, size: 4, alignment: 4, stack-id: default, local-offset: -4 }
machineFunctionInfo: {}
body: |
- bb.0.bb:
+ bb.0:
successors: %bb.1, %bb.2
liveins: $w1, $x0
@@ -198,30 +200,30 @@ body: |
renamable $w0 = MOVi32imm 1
B %bb.5
- bb.2.bb3:
+ bb.2:
successors: %bb.3, %bb.4
liveins: $w1, $x0
renamable $w9 = MOVi32imm 67305985
renamable $w8 = ORRWrs $wzr, renamable $w1, 0, implicit-def $x8
- STRWui killed renamable $w9, %stack.0.tmp, 0 :: (volatile store (s32) into %ir.tmp41)
+ STRWui killed renamable $w9, %stack.0.tmp, 0 :: (volatile store (s32) into %ir.tmp)
renamable $x9 = ADDXri %stack.0.tmp, 0, 0
- renamable $w10 = LDRBBroX renamable $x9, renamable $x8, 0, 0 :: (volatile load (s8) from %ir.tmp6)
+ renamable $w10 = LDRBBroX renamable $x9, renamable $x8, 0, 0 :: (volatile load (s8) from %ir.arg)
dead $wzr = SUBSWri killed renamable $w1, 2, 0, implicit-def $nzcv
- STRWui killed renamable $w10, renamable $x0, 0 :: (store (s32) into %ir.tmp92)
+ STRWui killed renamable $w10, renamable $x0, 0 :: (store (s32) into %ir.arg)
Bcc 8, %bb.4, implicit killed $nzcv
B %bb.3
- bb.3.bb11:
+ bb.3:
liveins: $x0, $x8, $x9
renamable $w8 = LDRBBroX killed renamable $x9, killed renamable $x8, 0, 0 :: (volatile load (s8) from %ir.sunkaddr)
STRWui killed renamable $w8, killed renamable $x0, 1 :: (store (s32) into %ir.tmp14)
- bb.4.bb15:
+ bb.4:
renamable $w0 = COPY $wzr
- bb.5.bb16:
+ bb.5:
liveins: $w0
RET_ReallyLR implicit $w0
More information about the llvm-commits
mailing list