LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 2206 - The bitwise-instruction optimizer doesn't know about alignment of globals.
Summary: The bitwise-instruction optimizer doesn't know about alignment of globals.
Status: RESOLVED FIXED
Alias: None
Product: new-bugs
Classification: Unclassified
Component: new bugs (show other bugs)
Version: unspecified
Hardware: PC Linux
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-07 19:40 PDT by Frits van Bommel
Modified: 2008-04-19 17:18 PDT (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Frits van Bommel 2008-04-07 19:40:23 PDT
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)*)".
Comment 1 Chris Lattner 2008-04-08 01:25:10 PDT
Please include a testcase, preferably in C form. Thanks!
Comment 2 Frits van Bommel 2008-04-08 02:08:34 PDT
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)
}
===
Comment 3 Dan Gohman 2008-04-10 14:51:43 PDT
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.