[llvm] r278409 - GlobalISel: support zext & sext during translation phase.

Tim Northover via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 11 14:01:10 PDT 2016


Author: tnorthover
Date: Thu Aug 11 16:01:10 2016
New Revision: 278409

URL: http://llvm.org/viewvc/llvm-project?rev=278409&view=rev
Log:
GlobalISel: support zext & sext during translation phase.

Modified:
    llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h
    llvm/trunk/include/llvm/Target/GenericOpcodes.td
    llvm/trunk/include/llvm/Target/TargetOpcodes.def
    llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll

Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h?rev=278409&r1=278408&r2=278409&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h Thu Aug 11 16:01:10 2016
@@ -176,6 +176,14 @@ private:
   }
   bool translateUnreachable(const User &U) { return true; }
 
+  bool translateSExt(const User &U) {
+    return translateCast(TargetOpcode::G_SEXT, U);
+  }
+
+  bool translateZExt(const User &U) {
+    return translateCast(TargetOpcode::G_ZEXT, U);
+  }
+
   /// Translate return (ret) instruction.
   /// The target needs to implement CallLowering::lowerReturn for
   /// this to succeed.
@@ -207,8 +215,6 @@ private:
   bool translateFence(const User &U) { return false; }
   bool translateAtomicCmpXchg(const User &U) { return false; }
   bool translateAtomicRMW(const User &U) { return false; }
-  bool translateSExt(const User &U) { return false; }
-  bool translateZExt(const User &U) { return false; }
   bool translateFPToUI(const User &U) { return false; }
   bool translateFPToSI(const User &U) { return false; }
   bool translateUIToFP(const User &U) { return false; }

Modified: llvm/trunk/include/llvm/Target/GenericOpcodes.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/GenericOpcodes.td?rev=278409&r1=278408&r2=278409&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/GenericOpcodes.td (original)
+++ llvm/trunk/include/llvm/Target/GenericOpcodes.td Thu Aug 11 16:01:10 2016
@@ -12,6 +12,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+//------------------------------------------------------------------------------
 // Unary ops.
 //------------------------------------------------------------------------------
 
@@ -23,6 +24,23 @@ def G_ANYEXTEND : Instruction {
   let hasSideEffects = 0;
 }
 
+// Sign extend the underlying scalar type of an operation, copying the sign bit
+// into the newly-created space.
+def G_SEXT : Instruction {
+  let OutOperandList = (outs unknown:$dst);
+  let InOperandList = (ins unknown:$src);
+  let hasSideEffects = 0;
+}
+
+// Zero extend the underlying scalar type of an operation, putting zero bits
+// into the newly-created space.
+def G_ZEXT : Instruction {
+  let OutOperandList = (outs unknown:$dst);
+  let InOperandList = (ins unknown:$src);
+  let hasSideEffects = 0;
+}
+
+
 // Truncate the underlying scalar type of an operation. This is equivalent to
 // G_EXTRACT for scalar types, but acts elementwise on vectors.
 def G_TRUNC : Instruction {
@@ -31,10 +49,6 @@ def G_TRUNC : Instruction {
   let hasSideEffects = 0;
 }
 
-//------------------------------------------------------------------------------
-// Unary ops.
-//------------------------------------------------------------------------------
-
 def G_FRAME_INDEX : Instruction {
   let OutOperandList = (outs unknown:$dst);
   let InOperandList = (ins unknown:$src2);

Modified: llvm/trunk/include/llvm/Target/TargetOpcodes.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetOpcodes.def?rev=278409&r1=278408&r2=278409&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetOpcodes.def (original)
+++ llvm/trunk/include/llvm/Target/TargetOpcodes.def Thu Aug 11 16:01:10 2016
@@ -232,6 +232,12 @@ HANDLE_TARGET_OPCODE(G_TRUNC)
 /// Generic integer constant.
 HANDLE_TARGET_OPCODE(G_CONSTANT)
 
+// Generic sign extend
+HANDLE_TARGET_OPCODE(G_SEXT)
+
+// Generic zero extend
+HANDLE_TARGET_OPCODE(G_ZEXT)
+
 /// Generic BRANCH instruction. This is an unconditional branch.
 HANDLE_TARGET_OPCODE(G_BR)
 

Modified: llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll?rev=278409&r1=278408&r2=278409&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll Thu Aug 11 16:01:10 2016
@@ -406,3 +406,21 @@ define i8* @test_constant_inttoptr() {
 define i64 @test_reused_constant() {
   ret i64 1
 }
+
+; CHECK-LABEL: name: test_sext
+; CHECK: [[IN:%[0-9]+]](32) = COPY %w0
+; CHECK: [[RES:%[0-9]+]](64) = G_SEXT { s64, s32 } [[IN]]
+; CHECK: %x0 = COPY [[RES]]
+define i64 @test_sext(i32 %in) {
+  %res = sext i32 %in to i64
+  ret i64 %res
+}
+
+; CHECK-LABEL: name: test_zext
+; CHECK: [[IN:%[0-9]+]](32) = COPY %w0
+; CHECK: [[RES:%[0-9]+]](64) = G_ZEXT { s64, s32 } [[IN]]
+; CHECK: %x0 = COPY [[RES]]
+define i64 @test_zext(i32 %in) {
+  %res = zext i32 %in to i64
+  ret i64 %res
+}




More information about the llvm-commits mailing list