xref: /llvm-project/llvm/test/Transforms/InstSimplify/ConstProp/cast-vector.ll (revision 475f30dfc83cda05b2e80edeb7b7b057e9f8ba38)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
3
4; Test constant fold of constant expression GEP used by ptrtoint (the
5; "offsetof-like expression" case).
6; This used to hit an assert due to not supporting vectors in
7; llvm::ConstantFoldCastInstruction when handling ptrtoint.
8define <2 x i16> @test1() {
9; CHECK-LABEL: @test1(
10; CHECK-NEXT:  entry:
11; CHECK-NEXT:    ret <2 x i16> ptrtoint (<2 x ptr> getelementptr inbounds ([10 x i32], ptr null, <2 x i64> zeroinitializer, <2 x i64> <i64 5, i64 7>) to <2 x i16>)
12;
13entry:
14  %gep = getelementptr inbounds [10 x i32], ptr null, i16 0, <2 x i16> <i16 5, i16 7>
15  %vec = ptrtoint <2 x ptr> %gep to <2 x i16>
16  ret <2 x i16> %vec
17}
18
19; Test constant fold of constant expression GEP used by ptrtoint (the
20; "sizeof-like expression" case).
21; This used to hit an assert due to not supporting vectors in
22; llvm::ConstantFoldCastInstruction when handling ptrtoint.
23define <2 x i16> @test2() {
24; CHECK-LABEL: @test2(
25; CHECK-NEXT:  entry:
26; CHECK-NEXT:    ret <2 x i16> ptrtoint (<2 x ptr> getelementptr (i32, ptr null, <2 x i64> <i64 5, i64 7>) to <2 x i16>)
27;
28entry:
29  %gep = getelementptr i32, ptr null, <2 x i16> <i16 5, i16 7>
30  %vec = ptrtoint <2 x ptr> %gep to <2 x i16>
31  ret <2 x i16> %vec
32}
33