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

The bitwise-instruction optimizer doesn't know about alignment of globals. #2578

Closed
llvmbot opened this issue Apr 8, 2008 · 5 comments
Closed
Labels
bugzilla Issues migrated from bugzilla

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Apr 8, 2008

Bugzilla Link 2206
Resolution FIXED
Resolved on Apr 19, 2008 17:18
Version unspecified
OS Linux
Reporter LLVM Bugzilla Contributor
CC @sunfishcode

Extended Description

Consider "i64 and (i64 ptrtoint (i64 (i64)* @​cons to i64), i64 -8)"[1].
(Where @​cons is a global function with an alignment >= 8 specified)
Such expressions aren't simplified by "opt -std-compile-opts", even though the relevant bits of the ptrtoint result are guaranteed to be zero because of above-mentioned alignment and similar optimizations are performed if the pointer is replaced by an integer.

[1]: That expression was shortened for readability, and not actually tested in this form. The actual expression was "i64 inttoptr (i64 and (i64 or (i64 ptrtoint (i64 (i64)* @​cons to i64), i64 1), i64 -8) to i64 (i64)*)".

@lattner
Copy link
Collaborator

lattner commented Apr 8, 2008

Please include a testcase, preferably in C form. Thanks!

@llvmbot
Copy link
Collaborator Author

llvmbot commented Apr 8, 2008

I couldn't get llvm-gcc to let me specify alignment on a function, but the same happens for other global data:

#include <stdlib.h>

int cons attribute ((aligned(8)));

unsigned long foo() {
return ((size_t) &cons) & 7;
}

output:

$ llvm-gcc -c llvm-func-and.c -emit-llvm -o out.bc -O3 && llvm-dis -o - out.bc
; ModuleID = 'out.bc'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
target triple = "x86_64-unknown-linux-gnu"
@​cons = weak global i32 0, align 8 ; <i32*> [#uses=1]

define i64 @​foo() nounwind {
entry:
ret i64 and (i64 ptrtoint (i32* @​cons to i64), i64 7)
}

@sunfishcode
Copy link
Member

With this:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20080407/060935.html
the bitwise-instruction optimizer now knows some things about alignment of globals.

However, the given testcase isn't yet simplified because it uses a constant expression
instead of instructions, so it would need to be simplified by the constant folder.

@lattner
Copy link
Collaborator

lattner commented Apr 20, 2008

@edwintorok
Copy link
Contributor

mentioned in issue llvm/llvm-bugzilla-archive#2240

@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
Projects
None yet
Development

No branches or pull requests

4 participants