[llvm-branch-commits] [llvm] bf286b0 - [X86][test] Improve global address offset folding tests

Fangrui Song via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Dec 29 21:44:43 PST 2020


Author: Fangrui Song
Date: 2020-12-29T21:39:29-08:00
New Revision: bf286b00e9e860a85adaab1214271e374267a033

URL: https://github.com/llvm/llvm-project/commit/bf286b00e9e860a85adaab1214271e374267a033
DIFF: https://github.com/llvm/llvm-project/commit/bf286b00e9e860a85adaab1214271e374267a033.diff

LOG: [X86][test] Improve global address offset folding tests

Added: 
    

Modified: 
    llvm/test/CodeGen/X86/fold-add.ll

Removed: 
    llvm/test/CodeGen/X86/fold-add-pcrel.ll


################################################################################
diff  --git a/llvm/test/CodeGen/X86/fold-add-pcrel.ll b/llvm/test/CodeGen/X86/fold-add-pcrel.ll
deleted file mode 100644
index 27a16b0ce61e..000000000000
--- a/llvm/test/CodeGen/X86/fold-add-pcrel.ll
+++ /dev/null
@@ -1,41 +0,0 @@
-; RUN: llc -mtriple=x86_64 -relocation-model=static < %s | FileCheck --check-prefixes=CHECK,STATIC %s
-; RUN: llc -mtriple=x86_64 -relocation-model=pic < %s | FileCheck --check-prefixes=CHECK,PIC %s
-; RUN: llc -mtriple=x86_64 -code-model=medium -relocation-model=static < %s | FileCheck --check-prefixes=CHECK,MSTATIC %s
-; RUN: llc -mtriple=x86_64 -code-model=medium -relocation-model=pic < %s | FileCheck --check-prefixes=CHECK,MPIC %s
-
- at foo = internal global i32 0
-
-define dso_local i64 @zero() {
-; CHECK-LABEL: zero:
-; CHECK:       # %bb.0:
-; STATIC-NEXT:   movl $foo, %eax
-; STATIC-NEXT:   retq
-; PIC-NEXT:      leaq foo(%rip), %rax
-; PIC-NEXT:      retq
-; MSTATIC-NEXT:  movabsq $foo, %rax
-; MSTATIC-NEXT:  retq
-; MPIC-NEXT:     leaq _GLOBAL_OFFSET_TABLE_(%rip), %rcx
-; MPIC-NEXT:     movabsq $foo at GOTOFF, %rax
-; MPIC-NEXT:     addq %rcx, %rax
-entry:
-  ret i64 add (i64 ptrtoint (i32* @foo to i64), i64 0)
-}
-
-;; Check we don't fold a large offset into leaq, otherwise
-;; the large r_addend can easily cause a relocation overflow.
-define dso_local i64 @large() {
-; CHECK-LABEL: large:
-; CHECK:       # %bb.0:
-; STATIC-NEXT:   movl $1701208431, %eax
-; STATIC-NEXT:   leaq foo(%rax), %rax
-; PIC-NEXT:      leaq foo(%rip), %rax
-; PIC-NEXT:      addq $1701208431, %rax
-; MSTATIC-NEXT:  movabsq $foo, %rax
-; MSTATIC-NEXT:  addq $1701208431, %rax
-; MSTATIC-NEXT:  retq
-; MPIC-NEXT:     leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
-; MPIC-NEXT:     movabsq $foo at GOTOFF, %rcx
-; MPIC-NEXT:     leaq 1701208431(%rax,%rcx), %rax
-entry:
-  ret i64 add (i64 ptrtoint (i32* @foo to i64), i64 1701208431)
-}

diff  --git a/llvm/test/CodeGen/X86/fold-add.ll b/llvm/test/CodeGen/X86/fold-add.ll
index e2d3b0588fe2..fc21e3b6e372 100644
--- a/llvm/test/CodeGen/X86/fold-add.ll
+++ b/llvm/test/CodeGen/X86/fold-add.ll
@@ -1,30 +1,105 @@
-; RUN: llc < %s | FileCheck %s
+; RUN: llc -mtriple=x86_64 -relocation-model=static < %s | FileCheck --check-prefixes=CHECK,STATIC %s
+; RUN: llc -mtriple=x86_64 -relocation-model=pic < %s | FileCheck --check-prefixes=CHECK,PIC %s
+; RUN: llc -mtriple=x86_64 -code-model=medium -relocation-model=static < %s | FileCheck --check-prefixes=CHECK,MSTATIC %s
+; RUN: llc -mtriple=x86_64 -code-model=medium -relocation-model=pic < %s | FileCheck --check-prefixes=CHECK,MPIC %s
 
-target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
-target triple = "x86_64-apple-darwin9.6"
- at prev_length = internal global i32 0		; <i32*> [#uses=1]
- at window = internal global [65536 x i8] zeroinitializer, align 32		; <[65536 x i8]*> [#uses=1]
- at llvm.used = appending global [1 x i8*] [i8* bitcast (i32 (i32)* @longest_match to i8*)]		; <[1 x i8*]*> [#uses=0]
+ at foo = internal global i32 0
 
-define fastcc i32 @longest_match(i32 %cur_match) nounwind {
-; CHECK-LABEL: longest_match:
-; CHECK-NOT: ret
-; CHECK: cmpb $0, (%r{{.*}},%r{{.*}})
-; CHECK: ret
+define dso_local i64 @zero() #0 {
+; CHECK-LABEL: zero:
+; CHECK:       # %bb.0:
+; STATIC-NEXT:   movl $foo, %eax
+; STATIC-NEXT:   retq
+; PIC-NEXT:      leaq foo(%rip), %rax
+; PIC-NEXT:      retq
+; MSTATIC-NEXT:  movabsq $foo, %rax
+; MSTATIC-NEXT:  retq
+; MPIC-NEXT:     leaq _GLOBAL_OFFSET_TABLE_(%rip), %rcx
+; MPIC-NEXT:     movabsq $foo at GOTOFF, %rax
+; MPIC-NEXT:     addq %rcx, %rax
+entry:
+  ret i64 add (i64 ptrtoint (i32* @foo to i64), i64 0)
+}
+
+define dso_local i64 @one() #0 {
+; CHECK-LABEL: one:
+; CHECK:       # %bb.0:
+; STATIC-NEXT:   movl $foo+1, %eax
+; PIC-NEXT:      leaq foo+1(%rip), %rax
+; MSTATIC-NEXT:  movabsq $foo, %rax
+; MSTATIC-NEXT:  incq %rax
+; MPIC-NEXT:     leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
+; MPIC-NEXT:     movabsq $foo at GOTOFF, %rcx
+; MPIC-NEXT:     leaq 1(%rax,%rcx), %rax
+entry:
+  ret i64 add (i64 ptrtoint (i32* @foo to i64), i64 1)
+}
+
+;; Check we don't fold a large offset into leaq, otherwise
+;; the large r_addend can easily cause a relocation overflow.
+define dso_local i64 @large() #0 {
+; CHECK-LABEL: large:
+; CHECK:       # %bb.0:
+; STATIC-NEXT:   movl $1701208431, %eax
+; STATIC-NEXT:   leaq foo(%rax), %rax
+; PIC-NEXT:      leaq foo(%rip), %rax
+; PIC-NEXT:      addq $1701208431, %rax
+; MSTATIC-NEXT:  movabsq $foo, %rax
+; MSTATIC-NEXT:  addq $1701208431, %rax
+; MSTATIC-NEXT:  retq
+; MPIC-NEXT:     leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
+; MPIC-NEXT:     movabsq $foo at GOTOFF, %rcx
+; MPIC-NEXT:     leaq 1701208431(%rax,%rcx), %rax
+entry:
+  ret i64 add (i64 ptrtoint (i32* @foo to i64), i64 1701208431)
+}
 
+define dso_local i64 @neg_1() #0 {
+; CHECK-LABEL: neg_1:
+; CHECK:       # %bb.0:
+; STATIC-NEXT:   movl $foo-1, %eax
+; PIC-NEXT:      leaq foo-1(%rip), %rax
+; MSTATIC-NEXT:  movabsq $foo, %rax
+; MSTATIC-NEXT:  decq %rax
+; MPIC-NEXT:     leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
+; MPIC-NEXT:     movabsq $foo at GOTOFF, %rcx
+; MPIC-NEXT:     leaq -1(%rax,%rcx), %rax
 entry:
-	%0 = load i32, i32* @prev_length, align 4		; <i32> [#uses=3]
-	%1 = zext i32 %cur_match to i64		; <i64> [#uses=1]
-	%2 = sext i32 %0 to i64		; <i64> [#uses=1]
-	%.sum3 = add i64 %1, %2		; <i64> [#uses=1]
-	%3 = getelementptr [65536 x i8], [65536 x i8]* @window, i64 0, i64 %.sum3		; <i8*> [#uses=1]
-	%4 = load i8, i8* %3, align 1		; <i8> [#uses=1]
-	%5 = icmp eq i8 %4, 0		; <i1> [#uses=1]
-	br i1 %5, label %bb5, label %bb23
-
-bb5:		; preds = %entry
-	ret i32 %0
-
-bb23:		; preds = %entry
-	ret i32 %0
+  ret i64 add (i64 ptrtoint (i32* @foo to i64), i64 -1)
 }
+
+define dso_local i64 @neg_0x80000000() #0 {
+; CHECK-LABEL: neg_0x80000000:
+; CHECK:       # %bb.0:
+; STATIC-NEXT:   movl $foo-2147483648, %eax
+; PIC-NEXT:      leaq foo-2147483648(%rip), %rax
+; MSTATIC-NEXT:  movabsq $foo, %rax
+; MSTATIC-NEXT:  addq $-2147483648, %rax
+; MPIC-NEXT:     leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
+; MPIC-NEXT:     movabsq $foo at GOTOFF, %rcx
+; MPIC-NEXT:     leaq -2147483648(%rax,%rcx), %rax
+entry:
+  ret i64 add (i64 ptrtoint (i32* @foo to i64), i64 -2147483648)
+}
+
+define dso_local i64 @neg_0x80000001() #0 {
+; CHECK-LABEL: neg_0x80000001:
+; CHECK:       # %bb.0:
+; STATIC-NEXT:   movabsq $-2147483649, %rax
+; STATIC-NEXT:   leaq foo(%rax), %rax
+; PIC-NEXT:      leaq foo(%rip), %rcx
+; PIC-NEXT:      movabsq $-2147483649, %rax
+; PIC-NEXT:      addq %rcx, %rax
+; MSTATIC-NEXT:  movabsq $-2147483649, %rcx
+; MSTATIC-NEXT:  movabsq $foo, %rax
+; MSTATIC-NEXT:  addq %rcx, %rax
+; MPIC-NEXT:     leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
+; MPIC-NEXT:     movabsq $foo at GOTOFF, %rcx
+; MPIC-NEXT:     addq %rax, %rcx
+; MPIC-NEXT:     movabsq $-2147483649, %rax
+; MPIC-NEXT:     addq %rcx, %rax
+entry:
+  ret i64 add (i64 ptrtoint (i32* @foo to i64), i64 -2147483649)
+}
+
+attributes #0 = { nounwind }


        


More information about the llvm-branch-commits mailing list