From 89cb961d01881967ef37937a67ce4839e03bc344 Mon Sep 17 00:00:00 2001 From: Daniel Sanders Date: Thu, 16 Mar 2017 18:04:50 +0000 Subject: [PATCH] [globalisel] Correct G_CONSTANT path of selectArithImmed() Earlier stages of GlobalISel always use ConstantInt in G_CONSTANT so that's what we should check for. This fixes a crash introduced in r297782. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297968 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/AArch64/AArch64InstructionSelector.cpp | 5 ++++- test/CodeGen/AArch64/GlobalISel/select-binop.mir | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Target/AArch64/AArch64InstructionSelector.cpp b/lib/Target/AArch64/AArch64InstructionSelector.cpp index e4f3fa86c13..6490d88a3c8 100644 --- a/lib/Target/AArch64/AArch64InstructionSelector.cpp +++ b/lib/Target/AArch64/AArch64InstructionSelector.cpp @@ -1246,7 +1246,10 @@ bool AArch64InstructionSelector::selectArithImmed( MachineInstr *Def = MRI.getVRegDef(Root.getReg()); if (Def->getOpcode() != TargetOpcode::G_CONSTANT) return false; - Immed = Def->getOperand(1).getImm(); + MachineOperand &Op1 = Def->getOperand(1); + if (!Op1.isCImm() || Op1.getCImm()->getBitWidth() > 64) + return false; + Immed = Op1.getCImm()->getZExtValue(); } else return false; diff --git a/test/CodeGen/AArch64/GlobalISel/select-binop.mir b/test/CodeGen/AArch64/GlobalISel/select-binop.mir index c922af710dc..7821bc0136a 100644 --- a/test/CodeGen/AArch64/GlobalISel/select-binop.mir +++ b/test/CodeGen/AArch64/GlobalISel/select-binop.mir @@ -137,7 +137,7 @@ body: | liveins: %w0, %w1 %0(s32) = COPY %w0 - %1(s32) = G_CONSTANT 1 + %1(s32) = G_CONSTANT i32 1 %2(s32) = G_ADD %0, %1 ... @@ -193,7 +193,7 @@ body: | successors: %bb.1 %0(s32) = COPY %w0 - %1(s32) = G_CONSTANT 1 + %1(s32) = G_CONSTANT i32 1 G_BR %bb.1 bb.1: -- 2.40.0