Skip to content

Commit 51f1cb5

Browse files
authored
[X86] Add or_is_add patterns for INC. (#87584)
Should fix the cases noted in #86857
1 parent 5b59ae4 commit 51f1cb5

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

llvm/lib/Target/X86/X86InstrCompiler.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,6 +2161,11 @@ multiclass EFLAGSDefiningPats<string suffix, Predicate p> {
21612161
def : Pat<(X86sub_flag_nocf GR16:$src, -1), (!cast<Instruction>(INC16r#suffix) GR16:$src)>;
21622162
def : Pat<(X86sub_flag_nocf GR32:$src, -1), (!cast<Instruction>(INC32r#suffix) GR32:$src)>;
21632163
def : Pat<(X86sub_flag_nocf GR64:$src, -1), (!cast<Instruction>(INC64r#suffix) GR64:$src)>;
2164+
2165+
def : Pat<(or_is_add GR8:$src, 1), (!cast<Instruction>(INC8r#suffix) GR8:$src)>;
2166+
def : Pat<(or_is_add GR16:$src, 1), (!cast<Instruction>(INC16r#suffix) GR16:$src)>;
2167+
def : Pat<(or_is_add GR32:$src, 1), (!cast<Instruction>(INC32r#suffix) GR32:$src)>;
2168+
def : Pat<(or_is_add GR64:$src, 1), (!cast<Instruction>(INC64r#suffix) GR64:$src)>;
21642169
}
21652170
}
21662171

llvm/test/CodeGen/X86/2009-05-23-dagcombine-shifts.ll

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
12
; RUN: llc < %s | FileCheck %s
23

34
; Check that the shr(shl X, 56), 48) is not mistakenly turned into
@@ -16,11 +17,13 @@ target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f3
1617
target triple = "x86_64-unknown-linux-gnu"
1718

1819
define i64 @foo(i64 %b) nounwind readnone {
19-
entry:
2020
; CHECK-LABEL: foo:
21-
; CHECK: movsbq %dil, %rax
22-
; CHECK: shlq $8, %rax
23-
; CHECK: orq $1, %rax
21+
; CHECK: # %bb.0: # %entry
22+
; CHECK-NEXT: movsbq %dil, %rax
23+
; CHECK-NEXT: shlq $8, %rax
24+
; CHECK-NEXT: incq %rax
25+
; CHECK-NEXT: retq
26+
entry:
2427
%shl = shl i64 %b, 56 ; <i64> [#uses=1]
2528
%shr = ashr i64 %shl, 48 ; <i64> [#uses=1]
2629
%add5 = or i64 %shr, 1 ; <i64> [#uses=1]

llvm/test/CodeGen/X86/load-local-v3i129.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ define void @_start() nounwind {
1212
; FAST-SHLD-NEXT: shrq $2, %rcx
1313
; FAST-SHLD-NEXT: shldq $2, %rdx, %rcx
1414
; FAST-SHLD-NEXT: andq $-4, %rax
15-
; FAST-SHLD-NEXT: orq $1, %rax
15+
; FAST-SHLD-NEXT: incq %rax
1616
; FAST-SHLD-NEXT: movq %rax, -40(%rsp)
1717
; FAST-SHLD-NEXT: movq %rcx, -32(%rsp)
1818
; FAST-SHLD-NEXT: orq $-2, -56(%rsp)
@@ -23,7 +23,7 @@ define void @_start() nounwind {
2323
; SLOW-SHLD: # %bb.0: # %Entry
2424
; SLOW-SHLD-NEXT: movq -40(%rsp), %rax
2525
; SLOW-SHLD-NEXT: andq $-4, %rax
26-
; SLOW-SHLD-NEXT: orq $1, %rax
26+
; SLOW-SHLD-NEXT: incq %rax
2727
; SLOW-SHLD-NEXT: movq %rax, -40(%rsp)
2828
; SLOW-SHLD-NEXT: orq $-2, -56(%rsp)
2929
; SLOW-SHLD-NEXT: movq $-1, -48(%rsp)

llvm/test/CodeGen/X86/pr23664.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ define i2 @f(i32 %arg) {
66
; CHECK: # %bb.0:
77
; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
88
; CHECK-NEXT: leal (%rdi,%rdi), %eax
9-
; CHECK-NEXT: orb $1, %al
9+
; CHECK-NEXT: incb %al
1010
; CHECK-NEXT: # kill: def $al killed $al killed $eax
1111
; CHECK-NEXT: retq
1212
%trunc = trunc i32 %arg to i1

0 commit comments

Comments
 (0)