The isOnlyUserOf prevented the fold if the chain result had any
users. What we really care about is the the data result from the
AND is only used by the TEST, and the flags results from the ANDs
aren't used at all. It's ok if the chain has users, we just need
to replace those users with the chain from the TESTrm.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/Target/X86/X86ISelDAGToDAG.cpp | ||
---|---|---|
1490 | AND32rm has 3 output. This check 1st output, should we also check 2nd output (EFLAGS) and only leave the 3rd (chain) output be used freely? |
llvm/lib/Target/X86/X86ISelDAGToDAG.cpp | ||
---|---|---|
1490 | See line 1496 and 1507. We have to check the opcode before we can tell if output 1 exists. |
llvm/lib/Target/X86/X86ISelDAGToDAG.cpp | ||
---|---|---|
1507 | Is the EFLAGS of AND32rm the same to the EFLAGS produced by TEST32mr? |
llvm/lib/Target/X86/X86ISelDAGToDAG.cpp | ||
---|---|---|
1507 | That's not quite the right question to ask because the EFLAGS of AND32rm were never used. The question to ask is does TEST32mr have the same EFLAGs as a TEST32rr of the AND32rm result register. Remember that the TEST32rr is doing an AND of the input with itself. They both internally do an AND and discard the result, but keep the flags which are calculated form the result. For TEST32mr this result will computed by ANDing the two inputs from the original AND32rm. For the TEST32rr it will AND a value with itself so the resulting values is just whatever original AND32rm computed. So for both TEST instruction this result value is the same. Let's look at each of the 6 flags |
llvm/lib/Target/X86/X86ISelDAGToDAG.cpp | ||
---|---|---|
1507 | Thank Craig for explaining. If And->hasAnyUseOfValue(1) is true. Can Value 1 be replaced by SDValue(Test, 0)? |
AND32rm has 3 output. This check 1st output, should we also check 2nd output (EFLAGS) and only leave the 3rd (chain) output be used freely?