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)*)".
Please include a testcase, preferably in C form. Thanks!
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) } ===
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.
implemented: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20080414/061282.html