Skip to content

Commit

Permalink
[GlobalISel] Generate selector for more integer binop patterns.
Browse files Browse the repository at this point in the history
This surprisingly isn't NFC because there are patterns to select GPR
sub to SUBSWrr (rather than SUBWrr/rs); SUBS is later optimized to
SUB if NZCV is dead.  From ISel's perspective, both are fine.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293010 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
ahmedbougacha committed Jan 25, 2017
1 parent 55e9554 commit c484c05
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 38 deletions.
16 changes: 16 additions & 0 deletions include/llvm/Target/GlobalISel/SelectionDAGCompat.td
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,20 @@ class GINodeEquiv<Instruction i, SDNode node> {
}

def : GINodeEquiv<G_ADD, add>;
def : GINodeEquiv<G_SUB, sub>;
def : GINodeEquiv<G_MUL, mul>;

def : GINodeEquiv<G_OR, or>;
def : GINodeEquiv<G_XOR, xor>;
def : GINodeEquiv<G_AND, and>;

def : GINodeEquiv<G_SHL, shl>;
def : GINodeEquiv<G_LSHR, srl>;
def : GINodeEquiv<G_ASHR, sra>;

def : GINodeEquiv<G_SDIV, sdiv>;
def : GINodeEquiv<G_UDIV, udiv>;
def : GINodeEquiv<G_SREM, srem>;
def : GINodeEquiv<G_UREM, urem>;

def : GINodeEquiv<G_BR, br>;
37 changes: 1 addition & 36 deletions lib/Target/AArch64/AArch64InstructionSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,57 +126,27 @@ static unsigned selectBinaryOp(unsigned GenericOpc, unsigned RegBankID,
unsigned OpSize) {
switch (RegBankID) {
case AArch64::GPRRegBankID:
if (OpSize <= 32) {
assert((OpSize == 32 || (GenericOpc != TargetOpcode::G_SDIV &&
GenericOpc != TargetOpcode::G_UDIV &&
GenericOpc != TargetOpcode::G_LSHR &&
GenericOpc != TargetOpcode::G_ASHR)) &&
"operation should have been legalized before now");

if (OpSize == 32) {
switch (GenericOpc) {
case TargetOpcode::G_OR:
return AArch64::ORRWrr;
case TargetOpcode::G_XOR:
return AArch64::EORWrr;
case TargetOpcode::G_AND:
return AArch64::ANDWrr;
case TargetOpcode::G_SUB:
return AArch64::SUBWrr;
case TargetOpcode::G_SHL:
return AArch64::LSLVWr;
case TargetOpcode::G_LSHR:
return AArch64::LSRVWr;
case TargetOpcode::G_ASHR:
return AArch64::ASRVWr;
case TargetOpcode::G_SDIV:
return AArch64::SDIVWr;
case TargetOpcode::G_UDIV:
return AArch64::UDIVWr;
default:
return GenericOpc;
}
} else if (OpSize == 64) {
switch (GenericOpc) {
case TargetOpcode::G_OR:
return AArch64::ORRXrr;
case TargetOpcode::G_XOR:
return AArch64::EORXrr;
case TargetOpcode::G_AND:
return AArch64::ANDXrr;
case TargetOpcode::G_GEP:
return AArch64::ADDXrr;
case TargetOpcode::G_SUB:
return AArch64::SUBXrr;
case TargetOpcode::G_SHL:
return AArch64::LSLVXr;
case TargetOpcode::G_LSHR:
return AArch64::LSRVXr;
case TargetOpcode::G_ASHR:
return AArch64::ASRVXr;
case TargetOpcode::G_SDIV:
return AArch64::SDIVXr;
case TargetOpcode::G_UDIV:
return AArch64::UDIVXr;
default:
return GenericOpc;
}
Expand Down Expand Up @@ -749,14 +719,9 @@ bool AArch64InstructionSelector::select(MachineInstr &I) const {
case TargetOpcode::G_FDIV:

case TargetOpcode::G_OR:
case TargetOpcode::G_XOR:
case TargetOpcode::G_AND:
case TargetOpcode::G_SHL:
case TargetOpcode::G_LSHR:
case TargetOpcode::G_ASHR:
case TargetOpcode::G_SDIV:
case TargetOpcode::G_UDIV:
case TargetOpcode::G_SUB:
case TargetOpcode::G_GEP: {
// Reject the various things we don't support yet.
if (unsupportedBinOp(I, RBI, MRI, TRI))
Expand Down
4 changes: 2 additions & 2 deletions test/CodeGen/AArch64/GlobalISel/arm64-instructionselect.mir
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ registers:
# CHECK: body:
# CHECK: %0 = COPY %w0
# CHECK: %1 = COPY %w1
# CHECK: %2 = SUBWrr %0, %1
# CHECK: %2 = SUBSWrr %0, %1
body: |
bb.0:
liveins: %w0, %w1
Expand Down Expand Up @@ -249,7 +249,7 @@ registers:
# CHECK: body:
# CHECK: %0 = COPY %x0
# CHECK: %1 = COPY %x1
# CHECK: %2 = SUBXrr %0, %1
# CHECK: %2 = SUBSXrr %0, %1
body: |
bb.0:
liveins: %x0, %x1
Expand Down

0 comments on commit c484c05

Please sign in to comment.