• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -S < %s -instcombine | FileCheck %s
2
3target datalayout = "e-p1:16:16-p2:32:32-p3:64:64"
4
5@G1 = global i32 42, align 1
6@G2 = global i32 42
7@G3 = global [4 x i8] zeroinitializer, align 1
8
9@A1 = alias i32, bitcast (i8* getelementptr inbounds ([4 x i8], [4 x i8]* @G3, i32 0, i32 2) to i32*)
10@A2 = alias i32, inttoptr (i64 and (i64 ptrtoint (i8* getelementptr inbounds ([4 x i8], [4 x i8]* @G3, i32 0, i32 3) to i64), i64 -4) to i32*)
11
12define i64 @f1() {
13; This cannot be constant folded because G1 is underaligned.
14; CHECK-LABEL: @f1(
15; CHECK: ret i64 and
16  ret i64 and (i64 ptrtoint (i32* @G1 to i64), i64 1)
17}
18
19define i64 @f2() {
20; The preferred alignment for G2 allows this one to foled to zero.
21; CHECK-LABEL: @f2(
22; CHECK: ret i64 0
23  ret i64 and (i64 ptrtoint (i32* @G2 to i64), i64 1)
24}
25
26define i64 @g1() {
27; This cannot be constant folded because A1 aliases G3 which is underalaigned.
28; CHECK-LABEL: @g1(
29; CHECK: ret i64 and
30  ret i64 and (i64 ptrtoint (i32* @A1 to i64), i64 1)
31}
32
33define i64 @g2() {
34; While A2 also aliases G3 which is underaligned, the math of A2 forces a
35; certain alignment allowing this to fold to zero.
36; CHECK-LABEL: @g2(
37; CHECK: ret i64 0
38  ret i64 and (i64 ptrtoint (i32* @A2 to i64), i64 1)
39}
40
41