GlobalISel: support 'null' constant in translation.
authorTim Northover <tnorthover@apple.com>
Thu, 11 Aug 2016 21:40:55 +0000 (21:40 +0000)
committerTim Northover <tnorthover@apple.com>
Thu, 11 Aug 2016 21:40:55 +0000 (21:40 +0000)
It's sharing the integer G_CONSTANT for now since I don't *think* it creates
any ambiguity (even on weird archs). If that turns out wrong we can create a
G_PTRCONSTANT or something.

llvm-svn: 278423

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll

index 5e07723..3f396cc 100644 (file)
@@ -296,6 +296,10 @@ bool IRTranslator::translate(const Constant &C, unsigned Reg) {
     EntryBuilder.buildConstant(LLT{*CI->getType()}, Reg, CI->getZExtValue());
   else if (isa<UndefValue>(C))
     EntryBuilder.buildInstr(TargetOpcode::IMPLICIT_DEF).addDef(Reg);
+  else if (isa<ConstantPointerNull>(C))
+    EntryBuilder.buildInstr(TargetOpcode::G_CONSTANT, LLT{*C.getType()})
+        .addDef(Reg)
+        .addImm(0);
   else if (auto CE = dyn_cast<ConstantExpr>(&C)) {
     switch(CE->getOpcode()) {
 #define HANDLE_INST(NUM, OPCODE, CLASS)                         \
index 68ac9fa..5987a4e 100644 (file)
@@ -458,3 +458,10 @@ define i32 @test_ashr(i32 %arg1, i32 %arg2) {
   %res = ashr i32 %arg1, %arg2
   ret i32 %res
 }
+
+; CHECK-LABEL: name: test_constant_null
+; CHECK: [[NULL:%[0-9]+]](64) = G_CONSTANT p0 0
+; CHECK: %x0 = COPY [[NULL]]
+define i8* @test_constant_null() {
+  ret i8* null
+}