Skip to content

Commit 8b8a483

Browse files
topperczmodem
authored andcommitted
[X86] Use MVT::i8 instead of MVT::i64 for shift amount in BuildSDIVPow2
X86 uses i8 for shift amounts. This code can fail on a 32-bit target if it runs after type legalization. This code was copied from AArch64 and modified for X86, but the shift amount wasn't changed to the correct type for X86. Fixes PR44812 (cherry picked from commit ec9a94a)
1 parent 3f4ba96 commit 8b8a483

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21056,7 +21056,7 @@ X86TargetLowering::BuildSDIVPow2(SDNode *N, const APInt &Divisor,
2105621056

2105721057
// Divide by pow2.
2105821058
SDValue SRA =
21059-
DAG.getNode(ISD::SRA, DL, VT, CMov, DAG.getConstant(Lg2, DL, MVT::i64));
21059+
DAG.getNode(ISD::SRA, DL, VT, CMov, DAG.getConstant(Lg2, DL, MVT::i8));
2106021060

2106121061
// If we're dividing by a positive value, we're done. Otherwise, we must
2106221062
// negate the result.

llvm/test/CodeGen/X86/pr44812.ll

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc < %s -mtriple=i386-unknown-linux-gnu -mattr=cmov | FileCheck %s
3+
4+
define <2 x i32> @foo(<2 x i32> %tmp) {
5+
; CHECK-LABEL: foo:
6+
; CHECK: # %bb.0: # %entry
7+
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
8+
; CHECK-NEXT: leal 7(%eax), %ecx
9+
; CHECK-NEXT: testl %eax, %eax
10+
; CHECK-NEXT: cmovnsl %eax, %ecx
11+
; CHECK-NEXT: sarl $3, %ecx
12+
; CHECK-NEXT: movl $1717986919, %eax # imm = 0x66666667
13+
; CHECK-NEXT: imull {{[0-9]+}}(%esp)
14+
; CHECK-NEXT: movl %edx, %eax
15+
; CHECK-NEXT: shrl $31, %eax
16+
; CHECK-NEXT: sarl $2, %edx
17+
; CHECK-NEXT: addl %edx, %eax
18+
; CHECK-NEXT: movl %ecx, %edx
19+
; CHECK-NEXT: retl
20+
entry:
21+
%tmp1 = sdiv <2 x i32> %tmp, <i32 10, i32 8>
22+
ret <2 x i32> %tmp1
23+
}
24+

0 commit comments

Comments
 (0)