Skip to content

Commit cff90f0

Browse files
committed
[SelectionDAG] Don't generate libcalls for wide shifts on Windows (PR42711)
Neither libgcc or compiler-rt are usually used on Windows, so these functions can't be called. Differential revision: https://reviews.llvm.org/D66880 llvm-svn: 370204
1 parent 3b44c36 commit cff90f0

File tree

6 files changed

+31
-11
lines changed

6 files changed

+31
-11
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12123,6 +12123,14 @@ bool AArch64TargetLowering::
1212312123
return X.getValueType().isScalarInteger() || NewShiftOpcode == ISD::SHL;
1212412124
}
1212512125

12126+
bool AArch64TargetLowering::shouldExpandShift(SelectionDAG &DAG,
12127+
SDNode *N) const {
12128+
if (DAG.getMachineFunction().getFunction().hasMinSize() &&
12129+
!Subtarget->isTargetWindows())
12130+
return false;
12131+
return true;
12132+
}
12133+
1212612134
void AArch64TargetLowering::initializeSplitCSR(MachineBasicBlock *Entry) const {
1212712135
// Update IsSplitCSR in AArch64unctionInfo.
1212812136
AArch64FunctionInfo *AFI = Entry->getParent()->getInfo<AArch64FunctionInfo>();

llvm/lib/Target/AArch64/AArch64ISelLowering.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,7 @@ class AArch64TargetLowering : public TargetLowering {
493493
unsigned OldShiftOpcode, unsigned NewShiftOpcode,
494494
SelectionDAG &DAG) const override;
495495

496-
bool shouldExpandShift(SelectionDAG &DAG, SDNode *N) const override {
497-
if (DAG.getMachineFunction().getFunction().hasMinSize())
498-
return false;
499-
return true;
500-
}
496+
bool shouldExpandShift(SelectionDAG &DAG, SDNode *N) const override;
501497

502498
bool shouldTransformSignedTruncationCheck(EVT XVT,
503499
unsigned KeptBits) const override {

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5104,6 +5104,14 @@ bool X86TargetLowering::shouldFoldMaskToVariableShiftPair(SDValue Y) const {
51045104
return true;
51055105
}
51065106

5107+
bool X86TargetLowering::shouldExpandShift(SelectionDAG &DAG,
5108+
SDNode *N) const {
5109+
if (DAG.getMachineFunction().getFunction().hasMinSize() &&
5110+
!Subtarget.isOSWindows())
5111+
return false;
5112+
return true;
5113+
}
5114+
51075115
bool X86TargetLowering::shouldSplatInsEltVarIndex(EVT VT) const {
51085116
// Any legal vector type can be splatted more efficiently than
51095117
// loading/spilling from memory.

llvm/lib/Target/X86/X86ISelLowering.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -873,11 +873,7 @@ namespace llvm {
873873
return VTIsOk(XVT) && VTIsOk(KeptBitsVT);
874874
}
875875

876-
bool shouldExpandShift(SelectionDAG &DAG, SDNode *N) const override {
877-
if (DAG.getMachineFunction().getFunction().hasMinSize())
878-
return false;
879-
return true;
880-
}
876+
bool shouldExpandShift(SelectionDAG &DAG, SDNode *N) const override;
881877

882878
bool shouldSplatInsEltVarIndex(EVT VT) const override;
883879

llvm/test/CodeGen/AArch64/shift_minsize.ll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
22
; RUN: llc < %s -mtriple=aarch64-unknown-unknown | FileCheck %s
3+
; RUN: llc < %s -mtriple=aarch64-windows | FileCheck %s -check-prefix=CHECK-WIN
4+
5+
; The Windows runtime doesn't have these.
6+
; CHECK-WIN-NOT: __ashlti3
7+
; CHECK-WIN-NOT: __ashrti3
38

49
define i64 @f0(i64 %val, i64 %amt) minsize optsize {
510
; CHECK-LABEL: f0:
@@ -53,6 +58,7 @@ define dso_local { i64, i64 } @shl128(i64 %x.coerce0, i64 %x.coerce1, i8 signext
5358
; CHECK-NEXT: bl __ashlti3
5459
; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
5560
; CHECK-NEXT: ret
61+
5662
entry:
5763
%x.sroa.2.0.insert.ext = zext i64 %x.coerce1 to i128
5864
%x.sroa.2.0.insert.shift = shl nuw i128 %x.sroa.2.0.insert.ext, 64

llvm/test/CodeGen/X86/shift_minsize.ll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2-
; RUN: llc < %s -mtriple=x86_64-unknown | FileCheck %s
2+
; RUN: llc < %s -mtriple=x86_64-unknown | FileCheck %s
3+
; RUN: llc < %s -mtriple=x86_64--windows-msvc | FileCheck %s -check-prefix=CHECK-WIN
4+
5+
; The Windows runtime doesn't have these.
6+
; CHECK-WIN-NOT: __ashlti3
7+
; CHECK-WIN-NOT: __ashrti3
8+
; CHECK-WIN-NOT: __lshrti3
39

410
define i64 @f0(i64 %val, i64 %amt) minsize optsize {
511
; CHECK-LABEL: f0:

0 commit comments

Comments
 (0)