]> granicus.if.org Git - llvm/commitdiff
GlobalISel: check for CImm rather than Imm on G_CONSTANTs.
authorTim Northover <tnorthover@apple.com>
Fri, 24 Feb 2017 21:21:38 +0000 (21:21 +0000)
committerTim Northover <tnorthover@apple.com>
Fri, 24 Feb 2017 21:21:38 +0000 (21:21 +0000)
All G_CONSTANTS created by the MachineIRBuilder have an operand of type CImm
(i.e. a ConstantInt), so that's what the selector needs to look for.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296176 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/GlobalISel/InstructionSelect.cpp
test/CodeGen/AArch64/GlobalISel/arm64-instructionselect-xor.mir

index a38ff00ed41f933511158629e53a0e58d76859e4..c1e4a8661a2d41506cd435c905f939367e3ad093 100644 (file)
@@ -20,6 +20,7 @@
 #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
 #include "llvm/CodeGen/MachineRegisterInfo.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
+#include "llvm/IR/Constants.h"
 #include "llvm/IR/Function.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
@@ -187,8 +188,10 @@ bool InstructionSelector::isOperandImmEqual(
     MachineInstr *Def = MRI.getVRegDef(MO.getReg());
     if (Def->getOpcode() != TargetOpcode::G_CONSTANT)
       return false;
-    assert(Def->getOperand(1).isImm() && "G_CONSTANT values must be constants");
-    return Def->getOperand(1).getImm() == Value;
+    assert(Def->getOperand(1).isCImm() &&
+           "G_CONSTANT values must be constants");
+    const ConstantInt &Imm = *Def->getOperand(1).getCImm();
+    return Imm.getBitWidth() <= 64 && Imm.getSExtValue() == Value;
   }
 
   return false;
index 2fd5588caddcc756a756022023590a104486d4de..722dddb20a789f5ea1c04e52f4d44e8728321286 100644 (file)
@@ -100,7 +100,7 @@ body:             |
     liveins: %w0
 
     %0(s32) = COPY %w0
-    %1(s32) = G_CONSTANT -1
+    %1(s32) = G_CONSTANT i64 -1
     %2(s32) = G_XOR %0, %1
 ...
 
@@ -128,7 +128,7 @@ body:             |
     liveins: %x0
 
     %0(s64) = COPY %x0
-    %1(s64) = G_CONSTANT -1
+    %1(s64) = G_CONSTANT i64 -1
     %2(s64) = G_XOR %0, %1
 ...
 
@@ -157,10 +157,9 @@ body:             |
   bb.0:
     liveins: %w0, %w1
     successors: %bb.1
-    %1(s32) = G_CONSTANT -1
+    %1(s32) = G_CONSTANT i64 -1
     G_BR %bb.1
   bb.1:
     %0(s32) = COPY %w0
     %2(s32) = G_XOR %0, %1
 ...
-