Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xor-inferring optimizations would be nice #1882

Closed
llvmbot opened this issue Jun 15, 2007 · 5 comments
Closed

xor-inferring optimizations would be nice #1882

llvmbot opened this issue Jun 15, 2007 · 5 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla code-quality

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Jun 15, 2007

Bugzilla Link 1510
Resolution FIXED
Resolved on Feb 22, 2010 12:40
Version trunk
OS MacOS X
Reporter LLVM Bugzilla Contributor

Extended Description

we don't currently infer that

~( ~(a|b) | (a&b) ) -> a^b

and similar, e.g. ~(~a & ~b) & ~(a&b) -> a^b

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jun 15, 2007

assigned to @lattner

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jun 15, 2007

Compile this with llvm-gcc:

unsigned int *a, *b;

void joy(void) {
a[20] = ((a[10]|b[10]) | (a[10]&b[10]));
}

and you get:

define void @​joy() {
entry:
%tmp = load i32** @​a ; <i32*> [#uses=2]
%tmp2 = getelementptr i32* %tmp, i32 10 ; <i32*> [#uses=1]
%tmp3 = load i32* %tmp2 ; [#uses=2]
%tmp4 = load i32** @​b ; <i32*> [#uses=1]
%tmp5 = getelementptr i32* %tmp4, i32 10 ; <i32*> [#uses=1]
%tmp6 = load i32* %tmp5 ; [#uses=2]
%tmp7 = or i32 %tmp6, %tmp3 ; [#uses=1]
%tmp7not = xor i32 %tmp7, -1 ; [#uses=1]
%tmp14 = and i32 %tmp6, %tmp3 ; [#uses=1]
%tmp15 = or i32 %tmp14, %tmp7not ; [#uses=1]
%tmp15not = xor i32 %tmp15, -1 ; [#uses=1]
%tmp16 = getelementptr i32* %tmp, i32 20 ; <i32*> [#uses=1]
store i32 %tmp15not, i32* %tmp16
ret void
}

it could just use xor?

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jun 15, 2007

@lattner
Copy link
Collaborator

lattner commented Jun 15, 2007

Here's a C vector example:

typedef unsigned attribute((vector_size(16))) vu;

vu test1(vu a, vu b) {
return ((a|b) | (a&b));
}

vu test2(vu a, vu b) {
return (a|b) & ~(a&b);
}

@lattner
Copy link
Collaborator

lattner commented Jun 15, 2007

Implemented. There are many patches to this, the primary ones being:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070611/050487.html
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070611/050489.html
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070611/050495.html

Testcase here: Transforms/InstCombine/and-or-not.ll

This shrunk Duraid's nasty example from 32K lines of x86-64 .s file to 23k lines.

-Chris

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla code-quality
Projects
None yet
Development

No branches or pull requests

2 participants