Skip to content

Commit e7bae9f

Browse files
committed
[X86] Allow rotate to be optimized by modulo shift.
The rotate uses the bottom 5 bits, so we can apply the same modulo we have here too.
1 parent 703f938 commit e7bae9f

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

llvm/lib/Target/X86/X86ISelDAGToDAG.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5464,6 +5464,8 @@ void X86DAGToDAGISel::Select(SDNode *Node) {
54645464
[[fallthrough]];
54655465
case ISD::SRA:
54665466
case ISD::SHL:
5467+
case ISD::ROTR:
5468+
case ISD::ROTL:
54675469
if (tryShiftAmountMod(Node))
54685470
return;
54695471
break;

llvm/test/CodeGen/X86/not-shift.ll

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,19 +1047,19 @@ define i64 @rotl64_sub63(i64 %val, i64 %cnt) nounwind {
10471047
;
10481048
; X64-NOBMI2-LABEL: rotl64_sub63:
10491049
; X64-NOBMI2: # %bb.0:
1050+
; X64-NOBMI2-NEXT: movq %rsi, %rcx
10501051
; X64-NOBMI2-NEXT: movq %rdi, %rax
1051-
; X64-NOBMI2-NEXT: movl $63, %ecx
1052-
; X64-NOBMI2-NEXT: subl %esi, %ecx
1053-
; X64-NOBMI2-NEXT: # kill: def $cl killed $cl killed $ecx
1052+
; X64-NOBMI2-NEXT: notl %ecx
1053+
; X64-NOBMI2-NEXT: # kill: def $cl killed $cl killed $rcx
10541054
; X64-NOBMI2-NEXT: rolq %cl, %rax
10551055
; X64-NOBMI2-NEXT: retq
10561056
;
10571057
; X64-BMI2-LABEL: rotl64_sub63:
10581058
; X64-BMI2: # %bb.0:
1059+
; X64-BMI2-NEXT: movq %rsi, %rcx
10591060
; X64-BMI2-NEXT: movq %rdi, %rax
1060-
; X64-BMI2-NEXT: movl $63, %ecx
1061-
; X64-BMI2-NEXT: subl %esi, %ecx
1062-
; X64-BMI2-NEXT: # kill: def $cl killed $cl killed $ecx
1061+
; X64-BMI2-NEXT: notl %ecx
1062+
; X64-BMI2-NEXT: # kill: def $cl killed $cl killed $rcx
10631063
; X64-BMI2-NEXT: rolq %cl, %rax
10641064
; X64-BMI2-NEXT: retq
10651065
%adj = sub i64 63, %cnt
@@ -1117,19 +1117,19 @@ define i64 @rotr64_sub63(i64 %val, i64 %cnt) nounwind {
11171117
;
11181118
; X64-NOBMI2-LABEL: rotr64_sub63:
11191119
; X64-NOBMI2: # %bb.0:
1120+
; X64-NOBMI2-NEXT: movq %rsi, %rcx
11201121
; X64-NOBMI2-NEXT: movq %rdi, %rax
1121-
; X64-NOBMI2-NEXT: movl $63, %ecx
1122-
; X64-NOBMI2-NEXT: subl %esi, %ecx
1123-
; X64-NOBMI2-NEXT: # kill: def $cl killed $cl killed $ecx
1122+
; X64-NOBMI2-NEXT: notl %ecx
1123+
; X64-NOBMI2-NEXT: # kill: def $cl killed $cl killed $rcx
11241124
; X64-NOBMI2-NEXT: rorq %cl, %rax
11251125
; X64-NOBMI2-NEXT: retq
11261126
;
11271127
; X64-BMI2-LABEL: rotr64_sub63:
11281128
; X64-BMI2: # %bb.0:
1129+
; X64-BMI2-NEXT: movq %rsi, %rcx
11291130
; X64-BMI2-NEXT: movq %rdi, %rax
1130-
; X64-BMI2-NEXT: movl $63, %ecx
1131-
; X64-BMI2-NEXT: subl %esi, %ecx
1132-
; X64-BMI2-NEXT: # kill: def $cl killed $cl killed $ecx
1131+
; X64-BMI2-NEXT: notl %ecx
1132+
; X64-BMI2-NEXT: # kill: def $cl killed $cl killed $rcx
11331133
; X64-BMI2-NEXT: rorq %cl, %rax
11341134
; X64-BMI2-NEXT: retq
11351135
%adj = sub i64 63, %cnt

llvm/test/CodeGen/X86/shift-amount-mod.ll

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,17 +1591,17 @@ define i32 @fshl32_by_negated(i32 %x, i32 %shamt) {
15911591
; X86-LABEL: fshl32_by_negated:
15921592
; X86: # %bb.0:
15931593
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
1594-
; X86-NEXT: movl $32, %ecx
1594+
; X86-NEXT: xorl %ecx, %ecx
15951595
; X86-NEXT: subl {{[0-9]+}}(%esp), %ecx
15961596
; X86-NEXT: # kill: def $cl killed $cl killed $ecx
15971597
; X86-NEXT: roll %cl, %eax
15981598
; X86-NEXT: retl
15991599
;
16001600
; X64-LABEL: fshl32_by_negated:
16011601
; X64: # %bb.0:
1602+
; X64-NEXT: movl %esi, %ecx
16021603
; X64-NEXT: movl %edi, %eax
1603-
; X64-NEXT: movl $32, %ecx
1604-
; X64-NEXT: subl %esi, %ecx
1604+
; X64-NEXT: negl %ecx
16051605
; X64-NEXT: # kill: def $cl killed $cl killed $ecx
16061606
; X64-NEXT: roll %cl, %eax
16071607
; X64-NEXT: retq
@@ -1615,17 +1615,17 @@ define i32 @fshr32_by_negated(i32 %x, i32 %shamt) {
16151615
; X86-LABEL: fshr32_by_negated:
16161616
; X86: # %bb.0:
16171617
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
1618-
; X86-NEXT: movl $32, %ecx
1618+
; X86-NEXT: xorl %ecx, %ecx
16191619
; X86-NEXT: subl {{[0-9]+}}(%esp), %ecx
16201620
; X86-NEXT: # kill: def $cl killed $cl killed $ecx
16211621
; X86-NEXT: rorl %cl, %eax
16221622
; X86-NEXT: retl
16231623
;
16241624
; X64-LABEL: fshr32_by_negated:
16251625
; X64: # %bb.0:
1626+
; X64-NEXT: movl %esi, %ecx
16261627
; X64-NEXT: movl %edi, %eax
1627-
; X64-NEXT: movl $32, %ecx
1628-
; X64-NEXT: subl %esi, %ecx
1628+
; X64-NEXT: negl %ecx
16291629
; X64-NEXT: # kill: def $cl killed $cl killed $ecx
16301630
; X64-NEXT: rorl %cl, %eax
16311631
; X64-NEXT: retq
@@ -1664,10 +1664,10 @@ define i64 @fshl64_by_negated(i64 %x, i64 %shamt) {
16641664
;
16651665
; X64-LABEL: fshl64_by_negated:
16661666
; X64: # %bb.0:
1667+
; X64-NEXT: movq %rsi, %rcx
16671668
; X64-NEXT: movq %rdi, %rax
1668-
; X64-NEXT: movl $64, %ecx
1669-
; X64-NEXT: subl %esi, %ecx
1670-
; X64-NEXT: # kill: def $cl killed $cl killed $ecx
1669+
; X64-NEXT: negl %ecx
1670+
; X64-NEXT: # kill: def $cl killed $cl killed $rcx
16711671
; X64-NEXT: rolq %cl, %rax
16721672
; X64-NEXT: retq
16731673
%neg = sub i64 64, %shamt
@@ -1705,10 +1705,10 @@ define i64 @fshr64_by_negated(i64 %x, i64 %shamt) {
17051705
;
17061706
; X64-LABEL: fshr64_by_negated:
17071707
; X64: # %bb.0:
1708+
; X64-NEXT: movq %rsi, %rcx
17081709
; X64-NEXT: movq %rdi, %rax
1709-
; X64-NEXT: movl $64, %ecx
1710-
; X64-NEXT: subl %esi, %ecx
1711-
; X64-NEXT: # kill: def $cl killed $cl killed $ecx
1710+
; X64-NEXT: negl %ecx
1711+
; X64-NEXT: # kill: def $cl killed $cl killed $rcx
17121712
; X64-NEXT: rorq %cl, %rax
17131713
; X64-NEXT: retq
17141714
%neg = sub i64 64, %shamt
@@ -1722,16 +1722,14 @@ define i32 @fshl32_add_k(i32 %x, i32 %shamt) {
17221722
; X86: # %bb.0:
17231723
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
17241724
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
1725-
; X86-NEXT: addl $32, %ecx
17261725
; X86-NEXT: # kill: def $cl killed $cl killed $ecx
17271726
; X86-NEXT: roll %cl, %eax
17281727
; X86-NEXT: retl
17291728
;
17301729
; X64-LABEL: fshl32_add_k:
17311730
; X64: # %bb.0:
1732-
; X64-NEXT: # kill: def $esi killed $esi def $rsi
1731+
; X64-NEXT: movl %esi, %ecx
17331732
; X64-NEXT: movl %edi, %eax
1734-
; X64-NEXT: leal 32(%rsi), %ecx
17351733
; X64-NEXT: # kill: def $cl killed $cl killed $ecx
17361734
; X64-NEXT: roll %cl, %eax
17371735
; X64-NEXT: retq
@@ -1770,9 +1768,9 @@ define i64 @fshr64_sub_k(i64 %x, i64 %shamt) {
17701768
;
17711769
; X64-LABEL: fshr64_sub_k:
17721770
; X64: # %bb.0:
1771+
; X64-NEXT: movq %rsi, %rcx
17731772
; X64-NEXT: movq %rdi, %rax
1774-
; X64-NEXT: leal -64(%rsi), %ecx
1775-
; X64-NEXT: # kill: def $cl killed $cl killed $ecx
1773+
; X64-NEXT: # kill: def $cl killed $cl killed $rcx
17761774
; X64-NEXT: rorq %cl, %rax
17771775
; X64-NEXT: retq
17781776
%k = sub i64 %shamt, 64

0 commit comments

Comments
 (0)