llvm.org GIT mirror llvm / 31fd198
[GlobalISel]: Add KnownBits for G_XOR https://reviews.llvm.org/D66119 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368648 91177308-0d34-0410-b5e6-96231b3b80d8 Aditya Nandakumar a month ago
2 changed file(s) with 29 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
130130 Known.Zero.setLowBits(KnownZeroLow);
131131 break;
132132 }
133 case TargetOpcode::G_XOR: {
134 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known, DemandedElts,
135 Depth + 1);
136 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known2, DemandedElts,
137 Depth + 1);
138
139 // Output known-0 bits are known if clear or set in both the LHS & RHS.
140 APInt KnownZeroOut = (Known.Zero & Known2.Zero) | (Known.One & Known2.One);
141 // Output known-1 are known to be set if set in only one of the LHS, RHS.
142 Known.One = (Known.Zero & Known2.One) | (Known.One & Known2.Zero);
143 Known.Zero = KnownZeroOut;
144 break;
145 }
133146 // G_GEP is like G_ADD. FIXME: Is this true for all targets?
134147 case TargetOpcode::G_GEP:
135148 case TargetOpcode::G_ADD: {
3939 EXPECT_EQ(256u, Res.One.getZExtValue());
4040 EXPECT_EQ(0xfffffeffu, Res.Zero.getZExtValue());
4141 }
42 TEST_F(GISelMITest, TestKnownBitsXOR) {
43 StringRef MIRString = " %3:_(s8) = G_CONSTANT i8 4\n"
44 " %4:_(s8) = G_CONSTANT i8 7\n"
45 " %5:_(s8) = G_XOR %3, %4\n"
46 " %6:_(s8) = COPY %5\n";
47 setUp(MIRString);
48 if (!TM)
49 return;
50 unsigned CopyReg = Copies[Copies.size() - 1];
51 MachineInstr *FinalCopy = MRI->getVRegDef(CopyReg);
52 unsigned SrcReg = FinalCopy->getOperand(1).getReg();
53 GISelKnownBits Info(*MF);
54 KnownBits Res = Info.getKnownBits(SrcReg);
55 EXPECT_EQ(3u, Res.One.getZExtValue());
56 EXPECT_EQ(252u, Res.Zero.getZExtValue());
57 }
4258
4359 TEST_F(GISelMITest, TestKnownBits) {
4460