This is an archive of the discontinued LLVM Phabricator instance.

[InstSimplify] Handle (~A & ~B) | (~A ^ B) -> ~A ^ B
ClosedPublic

Authored by craig.topper on Apr 24 2017, 4:38 PM.

Details

Summary

The code Sanjay Patel moved over from InstCombine doesn't work properly if the 'and' has both inputs as nots because we used a commuted op matcher on the 'and' first. But this will bind to the first 'not' on 'and' when there could be two 'not's. InstCombine could rely on DeMorgan to ensure the 'and' wouldn't have two 'not's eventually, but InstSimplify can't rely on that.

This patch matches the xor first then checks for the ands and allows a not of either operand of the xor.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Apr 24 2017, 4:38 PM
spatel edited edge metadata.Apr 25 2017, 6:25 AM

Nice catch. Just curious - did you find that by inspection or did it show up as a regression somewhere? I wonder if we should ease the one-use restrictions in the DeMorgan code in instcombine.

lib/Analysis/InstructionSimplify.cpp
1887–1888 ↗(On Diff #96482)

Can you add the other 2 patterns to the comment here? I get nervous when the listed formulas don't match the code...because usually we're missing some commuted possibility.

It was by inspection. I've been nervous about commutable matchers with m_Not (or really any opcode) that use m_Value and not m_Specific.

Add additional comments.

spatel accepted this revision.Apr 25 2017, 8:57 AM

LGTM.

This revision is now accepted and ready to land.Apr 25 2017, 8:57 AM
This revision was automatically updated to reflect the committed changes.