[llvm] [llvm][ARM]Add widen global arrays pass (PR #107120)

Nashe Mncube via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 7 04:14:04 PDT 2024


nasherm wrote:

> With the now updated pass I get the following output on the below (truncated) IR
> 
> **IR**
> 
> ```
> @.str = private unnamed_addr constant [10 x i8] c"123456789\00", align 1
> 
> ; Function Attrs: nounwind
> define hidden void @foo() #0 {
> entry:
>   %something = alloca [10 x i8], align 1
>   call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(10) %something, ptr noundef nonnull align 1 dereferenceable(10) @.str, i32 10, i1 false)
>   %call2 = call i32 @bar(ptr nonnull %something)
>   ret void
> }
> 
> 
> declare i32 @bar(...)
> ```

***AArch64***
**AArch64 (no pass) **
```
	.text
	.file	"example.ll"
	.hidden	foo                             // -- Begin function foo
	.globl	foo
	.p2align	2
	.type	foo, at function
foo:                                    // @foo
	.cfi_startproc
// %bb.0:                               // %entry
	sub	sp, sp, #32
	str	x30, [sp, #16]                  // 8-byte Folded Spill
	.cfi_def_cfa_offset 32
	.cfi_offset w30, -16
	adrp	x9, .L.str
	add	x9, x9, :lo12:.L.str
	mov	w8, #57                         // =0x39
	ldr	x9, [x9]
	mov	x0, sp
	strh	w8, [sp, #8]
	str	x9, [sp]
	bl	bar
	ldr	x30, [sp, #16]                  // 8-byte Folded Reload
	add	sp, sp, #32
	ret
.Lfunc_end0:
	.size	foo, .Lfunc_end0-foo
	.cfi_endproc
                                        // -- End function
	.type	.L.str, at object                  // @.str
	.section	.rodata.str1.1,"aMS", at progbits,1
.L.str:
	.asciz	"123456789"
	.size	.L.str, 10

	.section	".note.GNU-stack","", at progbits
```

**AArch64 (with pass)**
```
$ opt -passes=globalopt -mtriple=aarch64-none-eabi | llc -o - 
foo:                                    // @foo
	.cfi_startproc
// %bb.0:                               // %entry
	sub	sp, sp, #32
	str	x30, [sp, #16]                  // 8-byte Folded Spill
	.cfi_def_cfa_offset 32
	.cfi_offset w30, -16
	adrp	x9, .L.str
	add	x9, x9, :lo12:.L.str
	mov	w8, #57                         // =0x39
	ldr	x9, [x9]
	mov	x0, sp
	str	w8, [sp, #8]
	str	x9, [sp]
	bl	bar
	ldr	x30, [sp, #16]                  // 8-byte Folded Reload
	add	sp, sp, #32
	ret
.Lfunc_end0:
	.size	foo, .Lfunc_end0-foo
	.cfi_endproc
                                        // -- End function
	.type	.L.str, at object                  // @.str
	.section	.rodata,"a", at progbits
.L.str:
	.asciz	"123456789\000\000"
	.size	.L.str, 12

	.section	".note.GNU-stack","", at progbits

```

https://github.com/llvm/llvm-project/pull/107120


More information about the llvm-commits mailing list