1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -consthoist -consthoist-gep=1 -S | FileCheck %s
3
4; This is a reproducer for PR43903 where we hit an assertion:
5; opt: ../lib/Transforms/Scalar/ConstantHoisting.cpp:903: bool llvm::ConstantHoistingPass::emitBaseConstants(llvm::GlobalVariable *): Assertion `UsesNum == (ReBasesNum + NotRebasedNum) && "Not all uses are rebased"' failed.
6
7target triple = "x86_64-unknown-linux-gnu"
8
9@a = external global [2 x i16], align 1
10
11define void @c() {
12; CHECK-LABEL: @c(
13; CHECK-NEXT:  for.cond:
14; CHECK-NEXT:    br i1 undef, label [[FOR_BODY2:%.*]], label [[FOR_END4:%.*]]
15; CHECK:       for.body2:
16; CHECK-NEXT:    br i1 undef, label [[LAND_RHS:%.*]], label [[LAND_END:%.*]]
17; CHECK:       land.rhs:
18; CHECK-NEXT:    unreachable
19; CHECK:       land.end:
20; CHECK-NEXT:    [[CONST1:%.*]] = bitcast i16* getelementptr inbounds ([2 x i16], [2 x i16]* @a, i32 0, i32 0) to i16*
21; CHECK-NEXT:    [[CMP:%.*]] = icmp ule i16* undef, [[CONST1]]
22; CHECK-NEXT:    unreachable
23; CHECK:       for.cond3:
24; CHECK-NEXT:    [[TMP0:%.*]] = load i16, i16* getelementptr inbounds ([2 x i16], [2 x i16]* @a, i32 0, i32 1), align 1
25; CHECK-NEXT:    br label [[FOR_COND3:%.*]]
26; CHECK:       for.end4:
27; CHECK-NEXT:    [[CONST:%.*]] = bitcast i16* getelementptr inbounds ([2 x i16], [2 x i16]* @a, i32 0, i32 0) to i16*
28; CHECK-NEXT:    [[TMP1:%.*]] = load i16, i16* [[CONST]], align 1
29; CHECK-NEXT:    ret void
30;
31for.cond:
32  br i1 undef, label %for.body2, label %for.end4
33
34for.body2:                                        ; preds = %for.cond
35  br i1 undef, label %land.rhs, label %land.end
36
37land.rhs:                                         ; preds = %for.body2
38  unreachable
39
40land.end:                                         ; preds = %for.body2
41  %cmp = icmp ule i16* undef, getelementptr inbounds ([2 x i16], [2 x i16]* @a, i32 0, i32 0)
42  unreachable
43
44for.cond3:                                        ; preds = %for.cond3
45  %tmp0 = load i16, i16* getelementptr inbounds ([2 x i16], [2 x i16]* @a, i32 0, i32 1), align 1
46  br label %for.cond3
47
48for.end4:                                         ; preds = %for.cond
49  %tmp1 = load i16, i16* getelementptr inbounds ([2 x i16], [2 x i16]* @a, i32 0, i32 0), align 1
50  ret void
51}
52