[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:15:16 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(...)
> ```

***x86***

**x86 (no pass)**
```
$ opt -mtriple=x86_64-unknown-linux-gnu -S | llc -o -
	.text
	.file	"example.ll"
	.hidden	foo                             # -- Begin function foo
	.globl	foo
	.p2align	4, 0x90
	.type	foo, at function
foo:                                    # @foo
	.cfi_startproc
# %bb.0:                                # %entry
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movabsq	$4050765991979987505, %rax      # imm = 0x3837363534333231
	movq	%rax, 8(%rsp)
	movw	$57, 16(%rsp)
	leaq	8(%rsp), %rdi
	callq	bar at PLT
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	retq
.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
```

**x86(with pass)**
```
$ opt -mtriple=x86_64-unknown-linux-gnu  -passes=globalopt -S | llc -o -
	.text
	.file	"example.ll"
	.hidden	foo                             # -- Begin function foo
	.globl	foo
	.p2align	4, 0x90
	.type	foo, at function
foo:                                    # @foo
	.cfi_startproc
# %bb.0:                                # %entry
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movabsq	$4050765991979987505, %rax      # imm = 0x3837363534333231
	movq	%rax, 8(%rsp)
	movl	$57, 16(%rsp)
	leaq	8(%rsp), %rdi
	callq	bar at PLT
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	retq
.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