xref: /llvm-project/llvm/test/Transforms/InstCombine/constant-fold-alias.ll (revision 625113402f9febd4d8c907a342ea09a3c0982ba8)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2; RUN: opt -S < %s -passes=instcombine | FileCheck %s
3
4target datalayout = "e-p1:16:16-p2:32:32-p3:64:64"
5
6@G1 = global i32 42, align 1
7@G2 = global i32 42
8@G3 = global [4 x i8] zeroinitializer, align 1
9
10@A1 = alias i32, getelementptr inbounds ([4 x i8], ptr @G3, i32 0, i32 2)
11
12define i64 @f1() {
13; This cannot be constant folded because G1 is underaligned.
14; CHECK-LABEL: define i64 @f1() {
15; CHECK-NEXT:    [[AND:%.*]] = and i64 ptrtoint (ptr @G1 to i64), 1
16; CHECK-NEXT:    ret i64 [[AND]]
17;
18  %and = and i64 ptrtoint (ptr @G1 to i64), 1
19  ret i64 %and
20}
21
22define i64 @f2() {
23; The preferred alignment for G2 allows this one to foled to zero.
24; CHECK-LABEL: define i64 @f2() {
25; CHECK-NEXT:    ret i64 0
26;
27  %and = and i64 ptrtoint (ptr @G2 to i64), 1
28  ret i64 %and
29}
30
31define i64 @g1() {
32; This cannot be constant folded because A1 aliases G3 which is underalaigned.
33; CHECK-LABEL: define i64 @g1() {
34; CHECK-NEXT:    [[AND:%.*]] = and i64 ptrtoint (ptr @A1 to i64), 1
35; CHECK-NEXT:    ret i64 [[AND]]
36;
37  %and = and i64 ptrtoint (ptr @A1 to i64), 1
38  ret i64 %and
39}
40