1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=instcombine < %s | FileCheck %s
4 declare void @llvm.assume(i1 noundef)
6 ; Just something to let us check that separate_storage bundles don't break
7 ; anything when given an operand that's not an instruction to fold.
8 @some_global = global i32 777
10 define void @simple_folding(ptr %a, ptr %b) {
11 ; CHECK-LABEL: @simple_folding(
13 ; CHECK-NEXT: call void @llvm.assume(i1 true) [ "separate_storage"(ptr [[A:%.*]], ptr [[B:%.*]]) ]
14 ; CHECK-NEXT: ret void
17 %p1 = getelementptr i8, ptr %a, i64 123
18 %p2 = getelementptr i8, ptr %b, i64 777
19 call void @llvm.assume(i1 1) ["separate_storage"(ptr %p1, ptr %p2)]
23 define i64 @folds_removed_operands(ptr %a, ptr %b, i64 %n1, i64 %n2) {
24 ; CHECK-LABEL: @folds_removed_operands(
26 ; CHECK-NEXT: [[REASS_ADD:%.*]] = shl i64 [[N2:%.*]], 1
27 ; CHECK-NEXT: [[Y:%.*]] = add i64 [[N1:%.*]], [[REASS_ADD]]
28 ; CHECK-NEXT: call void @llvm.assume(i1 true) [ "separate_storage"(ptr [[A:%.*]], ptr [[B:%.*]]) ]
29 ; CHECK-NEXT: ret i64 [[Y]]
32 ; Ordinarily, n1 + n2 + n2 would get canonicalized into n1 + (n2 << 1) unless
33 ; there's another use of n1 + n2. Make sure that we remember to put removed
34 ; arguments to separate_storage bundles back on the worklist.
37 %p1 = getelementptr i8, ptr %a, i64 %x
38 call void @llvm.assume(i1 1) ["separate_storage"(ptr %p1, ptr %b)]
42 define void @handles_globals(ptr %a) {
43 ; CHECK-LABEL: @handles_globals(
44 ; CHECK-NEXT: call void @llvm.assume(i1 true) [ "separate_storage"(ptr [[A:%.*]], ptr @some_global) ]
45 ; CHECK-NEXT: ret void
47 %derived = getelementptr i8, ptr @some_global, i65 3
48 call void @llvm.assume(i1 1) ["separate_storage"(ptr %a, ptr %derived)]