]> granicus.if.org Git - llvm/commitdiff
GlobalISel: constrain G_INSERT to inserting just one value per instruction.
authorTim Northover <tnorthover@apple.com>
Fri, 3 Mar 2017 23:05:47 +0000 (23:05 +0000)
committerTim Northover <tnorthover@apple.com>
Fri, 3 Mar 2017 23:05:47 +0000 (23:05 +0000)
It's much easier to reason about single-value inserts and no-one was actually
using the variadic variants before.

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

include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
include/llvm/Target/GenericOpcodes.td
lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
lib/Target/AArch64/AArch64LegalizerInfo.cpp
test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
test/CodeGen/AArch64/GlobalISel/irtranslator-exceptions.ll
test/CodeGen/AArch64/GlobalISel/legalize-inserts.mir

index d7fe1c4f63e2ed9caab476f58ce28ec4b9155c9e..7d148cf2e9a963922ee63973d8d198cee13dd3c2 100644 (file)
@@ -511,14 +511,8 @@ public:
     return MIB;
   }
 
-  template <typename... ArgTys>
   MachineInstrBuilder buildInsert(unsigned Res, unsigned Src,
-                                  unsigned Op, unsigned Index, ArgTys... Args) {
-    MachineInstrBuilder MIB =
-        buildInstr(TargetOpcode::G_INSERT).addDef(Res).addUse(Src);
-    addUsesWithIndices(MIB, Op, Index, Args...);
-    return MIB;
-  }
+                                  unsigned Op, unsigned Index);
 
   /// Build and insert either a G_INTRINSIC (if \p HasSideEffects is false) or
   /// G_INTRINSIC_W_SIDE_EFFECTS instruction. Its first operand will be the
index fecdd72d6a5f71d5e40a6d215ec63645aa9da4d5..5eb95d5da7888e440bdf8ff7f6ccdb50b56bcb0e 100644 (file)
@@ -443,12 +443,10 @@ def G_UNMERGE_VALUES : Instruction {
   let hasSideEffects = 0;
 }
 
-// Insert a sequence of smaller registers into a larger one at the specified
-// indices (interleaved with the values in the operand list "op0, bit0, op1,
-// bit1, ...")).
+// Insert a smaller register into a larger one at the specified bit-index.
 def G_INSERT : Instruction {
   let OutOperandList = (outs type0:$dst);
-  let InOperandList = (ins type0:$src, variable_ops);
+  let InOperandList = (ins type0:$src, type1:$op, unknown:$offset);
   let hasSideEffects = 0;
 }
 
index 41985e3a32815ea638ca73f480a7fa87dc5bccd3..5eea7268c5e7df21c0718a236f9bf107fe319d19 100644 (file)
@@ -456,6 +456,15 @@ MachineInstrBuilder MachineIRBuilder::buildUnmerge(ArrayRef<unsigned> Res,
   return MIB;
 }
 
+MachineInstrBuilder MachineIRBuilder::buildInsert(unsigned Res, unsigned Src,
+                                                  unsigned Op, unsigned Index) {
+  return buildInstr(TargetOpcode::G_INSERT)
+      .addDef(Res)
+      .addUse(Src)
+      .addUse(Op)
+      .addImm(Index);
+}
+
 MachineInstrBuilder MachineIRBuilder::buildIntrinsic(Intrinsic::ID ID,
                                                      unsigned Res,
                                                      bool HasSideEffects) {
index 651925e616f9a98fab31c8d6eef8b67e989853fa..6e6daf8122951526b1c0973a964358985ce66f99 100644 (file)
@@ -88,14 +88,13 @@ AArch64LegalizerInfo::AArch64LegalizerInfo() {
     setAction({BinOp, s64}, Libcall);
   }
 
-  // FIXME: what should we do about G_INSERTs with more than one source value?
-  // For now the default of not specifying means we'll fall back.
-  for (auto Ty : {s32, s64}) {
+  for (auto Ty : {s32, s64, p0}) {
     setAction({G_INSERT, Ty}, Legal);
     setAction({G_INSERT, 1, Ty}, Legal);
   }
   for (auto Ty : {s1, s8, s16}) {
     setAction({G_INSERT, Ty}, WidenScalar);
+    setAction({G_INSERT, 1, Ty}, Legal);
     // FIXME: Can't widen the sources because that violates the constraints on
     // G_INSERT (It seems entirely reasonable that inputs shouldn't overlap).
   }
index 3c06d5c80f7b10135510e86539b77f08a0528423..a05c4a8fe4121aab14700567f71bfb0e09221fec 100644 (file)
@@ -881,7 +881,7 @@ define void @test_extractvalue_agg(%struct.nested* %addr, {i8, i32}* %addr2) {
 ; CHECK-LABEL: name: test_insertvalue
 ; CHECK: [[VAL:%[0-9]+]](s32) = COPY %w1
 ; CHECK: [[STRUCT:%[0-9]+]](s128) = G_LOAD
-; CHECK: [[NEWSTRUCT:%[0-9]+]](s128) = G_INSERT [[STRUCT]](s128), [[VAL]](s32), 64
+; CHECK: [[NEWSTRUCT:%[0-9]+]](s128) = G_INSERT [[STRUCT]], [[VAL]](s32), 64
 ; CHECK: G_STORE [[NEWSTRUCT]](s128),
 define void @test_insertvalue(%struct.nested* %addr, i32 %val) {
   %struct = load %struct.nested, %struct.nested* %addr
@@ -893,7 +893,7 @@ define void @test_insertvalue(%struct.nested* %addr, i32 %val) {
 ; CHECK-LABEL: name: test_insertvalue_agg
 ; CHECK: [[SMALLSTRUCT:%[0-9]+]](s64) = G_LOAD
 ; CHECK: [[STRUCT:%[0-9]+]](s128) = G_LOAD
-; CHECK: [[RES:%[0-9]+]](s128) = G_INSERT [[STRUCT]](s128), [[SMALLSTRUCT]](s64), 32
+; CHECK: [[RES:%[0-9]+]](s128) = G_INSERT [[STRUCT]], [[SMALLSTRUCT]](s64), 32
 ; CHECK: G_STORE [[RES]](s128)
 define void @test_insertvalue_agg(%struct.nested* %addr, {i8, i32}* %addr2) {
   %smallstruct = load {i8, i32}, {i8, i32}* %addr2
index 5469c6c56343b99133ff366add247574cf145abb..be9ee333d103b01f1275f581a8fab445dab3e4e6 100644 (file)
@@ -29,7 +29,7 @@ declare i32 @llvm.eh.typeid.for(i8*)
 
 ; CHECK:   [[GOOD]]:
 ; CHECK:     [[SEL:%[0-9]+]](s32) = G_CONSTANT i32 1
-; CHECK:     {{%[0-9]+}}(s128) = G_INSERT {{%[0-9]+}}(s128), [[SEL]](s32), 64
+; CHECK:     {{%[0-9]+}}(s128) = G_INSERT {{%[0-9]+}}, [[SEL]](s32), 64
 
 define { i8*, i32 } @bar() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
   %res32 = invoke i32 @foo(i32 42) to label %continue unwind label %broken
index 0596314c60efd7a392c0c0f15d9144d2e8d674be..d7e853e69b32c5fc59d464a306908656d05e97fa 100644 (file)
@@ -43,7 +43,7 @@ body: |
     ; CHECK-LABEL: name: test_inserts_2
     ; CHECK: [[LO:%[0-9]+]](s64) = G_LOAD
     ; CHECK: [[HI:%[0-9]+]](s64) = G_LOAD
-    ; CHECK: [[NEWHI:%[0-9]+]](s64) = G_INSERT [[HI]](s64), %1(s32), 0
+    ; CHECK: [[NEWHI:%[0-9]+]](s64) = G_INSERT [[HI]], %1(s32), 0
     ; CHECK: G_STORE %0(s64)
     ; CHECK: G_STORE [[NEWHI]]
     %0:_(s64) = COPY %x0
@@ -68,7 +68,7 @@ body: |
     ; CHECK-LABEL: name: test_inserts_3
     ; CHECK: [[LO:%[0-9]+]](s64) = G_LOAD
     ; CHECK: [[HI:%[0-9]+]](s64) = G_LOAD
-    ; CHECK: [[NEWLO:%[0-9]+]](s64) = G_INSERT [[LO]](s64), %0(p0), 0
+    ; CHECK: [[NEWLO:%[0-9]+]](s64) = G_INSERT [[LO]], %0(p0), 0
     ; CHECK: G_STORE [[NEWLO]](s64)
     ; CHECK: G_STORE [[HI]]
     %0:_(p0) = COPY %x0
@@ -89,7 +89,7 @@ body: |
       ; A narrow insert gets surrounded by a G_ANYEXT/G_TRUNC pair.
     ; CHECK-LABEL: name: test_inserts_4
     ; CHECK: [[VALEXT:%[0-9]+]](s32) = G_ANYEXT %1(s8)
-    ; CHECK: [[VAL:%[0-9]+]](s32) = G_INSERT [[VALEXT]](s32), %0(s1), 0
+    ; CHECK: [[VAL:%[0-9]+]](s32) = G_INSERT [[VALEXT]], %0(s1), 0
     ; CHECK: %3(s8) = G_TRUNC [[VAL]](s32)
     %0:_(s1) = COPY %w0
     %1:_(s8) = COPY %w1