]> granicus.if.org Git - llvm/commitdiff
[globalisel] Support trivial COPY in GISelKnownBits
authorDaniel Sanders <daniel_l_sanders@apple.com>
Wed, 4 Sep 2019 18:59:43 +0000 (18:59 +0000)
committerDaniel Sanders <daniel_l_sanders@apple.com>
Wed, 4 Sep 2019 18:59:43 +0000 (18:59 +0000)
Summary: Allow GISelKnownBits to look through the trivial case of TargetOpcode::COPY

Reviewers: aditya_nandakumar

Subscribers: rovka, hiraditya, volkan, Petar.Avramovic, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D67131

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

lib/CodeGen/GlobalISel/GISelKnownBits.cpp
unittests/CodeGen/GlobalISel/KnownBitsTest.cpp

index 057a32fd1d5aa941af801c4f4fc448ed1acf067a..72ffd4412333097572787f797561dbc27d6a2221 100644 (file)
@@ -112,6 +112,19 @@ void GISelKnownBits::computeKnownBitsImpl(Register R, KnownBits &Known,
   default:
     TL.computeKnownBitsForTargetInstr(R, Known, DemandedElts, MRI, Depth);
     break;
+  case TargetOpcode::COPY: {
+    MachineOperand Dst = MI.getOperand(0);
+    MachineOperand Src = MI.getOperand(1);
+    // Look through trivial copies.
+    // We can't use NoSubRegister by name as it's defined by each target but
+    // it's always defined to be 0 by tablegen.
+    if (Dst.getSubReg() == 0 /*NoSubRegister*/ && Src.getReg().isVirtual() &&
+        Src.getSubReg() == 0 /*NoSubRegister*/) {
+      // Don't increment Depth for this one since we didn't do any work.
+      computeKnownBitsImpl(Src.getReg(), Known, DemandedElts, Depth);
+    }
+    break;
+  }
   case TargetOpcode::G_CONSTANT: {
     auto CstVal = getConstantVRegVal(R, MRI);
     Known.One = *CstVal;
index 42d676f4a00e595e69439f0fd64a2f78f53128ec..7f698ac1cd1d8e258f1348609cb03d787a047e80 100644 (file)
@@ -19,11 +19,17 @@ TEST_F(GISelMITest, TestKnownBitsCst) {
   unsigned CopyReg = Copies[Copies.size() - 1];
   MachineInstr *FinalCopy = MRI->getVRegDef(CopyReg);
   unsigned SrcReg = FinalCopy->getOperand(1).getReg();
+  unsigned DstReg = FinalCopy->getOperand(1).getReg();
   GISelKnownBits Info(*MF);
   KnownBits Res = Info.getKnownBits(SrcReg);
   EXPECT_EQ((uint64_t)1, Res.One.getZExtValue());
   EXPECT_EQ((uint64_t)0xfe, Res.Zero.getZExtValue());
+
+  KnownBits Res2 = Info.getKnownBits(DstReg);
+  EXPECT_EQ(Res.One.getZExtValue(), Res2.One.getZExtValue());
+  EXPECT_EQ(Res.Zero.getZExtValue(), Res2.Zero.getZExtValue());
 }
+
 TEST_F(GISelMITest, TestKnownBitsPtrToIntViceVersa) {
   StringRef MIRString = "  %3:_(s16) = G_CONSTANT i16 256\n"
                         "  %4:_(p0) = G_INTTOPTR %3\n"