This patch implements transform for pattern "(A ^ B) | ((~A) ^ B) -> True".

Please help in reviewing the same.

Thanks,

Sonam.

Differential D4691

Added InstCombine transform for pattern "(A ^ B) | ((~A) ^ B) -> True".

Authored by **sonamkumari** on Jul 27 2014, 11:42 PM.

Details

Diff Detail

lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | ||
---|---|---|

1283 ↗ | (On Diff #11938) | This change seems irrelevant to the patch. |

1986–1989 ↗ | (On Diff #11938) | See my comments in your other differential, D4690. |

test/Transforms/InstCombine/or.ll | ||

411–420 ↗ | (On Diff #11938) | Again, please see my comments in D4690. |

Comment Actions

Hi David,

Thanks for your valuable review comments.

I have made the changes as you mentioned.

Please help in reviewing the patch.

Thanks,

Sonam.

Comment Actions

Thinking about this with some colleagues, I'm starting to believe that this can be fixed in a more general way.

We do not optimize `(A ^ B) | ((A ^ -1) ^ B)` but we correctly optimize `(A ^ B) | ((A ^ B) ^ -1)`; this makes me think that we are looking at a bug in reassociate.

lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|

1606 | This comment looks wrong, it should probably be: // (A ^ B) | ((~A) ^ B) = -1 |

Comment Actions

I've gone ahead and fixed this in rL214342; it includes a more general transform which should handle more cases.

Comment Actions

Hi David,

Thanks for your valuable comments.I will try to consider general case while doing any optimization in future.

But the patch which you uploaded in rL214342 fails for the following test cases as it doesn't take into consideration the symmetric case.

The test cases for which it fails are :

define i32 @test14(i32 %x, i32 %y) {

%nega = xor i32 %x, -1 %xor = xor i32 %nega, %y %xor1 = xor i32 %x, %y %or = or i32 %xor, %xor1 ret i32 %or

}

define i32 @test15(i32 %x, i32 %y) {

%xor = xor i32 %x, %y %nega = xor i32 %x, -1 %xor1 = xor i32 %nega, %y %or = or i32 %xor, %xor1 ret i32 %or

}

So, I modified the patch and submitting the same.

Kindly review it.

Thanks,

Sonam.

Comment Actions

I don't think we need to do anything here, running reassociate before instcombine cleans things up.

$ cat t.ll define i32 @test14(i32 %x, i32 %y) { %nega = xor i32 %x, -1 %xor = xor i32 %nega, %y %xor1 = xor i32 %x, %y %or = or i32 %xor, %xor1 ret i32 %or } define i32 @test15(i32 %x, i32 %y) { %xor = xor i32 %x, %y %nega = xor i32 %x, -1 %xor1 = xor i32 %nega, %y %or = or i32 %xor, %xor1 ret i32 %or } $ ~/llvm/Debug+Asserts/bin/opt -reassociate -instcombine t.ll -o - -S ; ModuleID = 't.ll' define i32 @test14(i32 %x, i32 %y) { ret i32 -1 } define i32 @test15(i32 %x, i32 %y) { ret i32 -1 }