1; REQUIRES: asserts 2; RUN: llc -mcpu=haswell < %s -stats -O2 2>&1 | grep "7 machinelicm.*hoisted" 3; For test: 4; 2 invariant loads, 1 for OBJC_SELECTOR_REFERENCES_ 5; and 1 for objc_msgSend from the GOT 6; For test_multi_def: 7; 2 invariant load (full multiply, both loads should be hoisted.) 8; For test_div_def: 9; 2 invariant load (full divide, both loads should be hoisted.) 1 additional instruction for a zeroing edx that gets hoisted and then rematerialized. 10 11target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" 12target triple = "x86_64-apple-macosx10.7.2" 13 14@"\01L_OBJC_METH_VAR_NAME_" = internal global [4 x i8] c"foo\00", section "__TEXT,__objc_methname,cstring_literals", align 1 15@"\01L_OBJC_SELECTOR_REFERENCES_" = internal global i8* getelementptr inbounds ([4 x i8], [4 x i8]* @"\01L_OBJC_METH_VAR_NAME_", i64 0, i64 0), section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip" 16@"\01L_OBJC_IMAGE_INFO" = internal constant [2 x i32] [i32 0, i32 16], section "__DATA, __objc_imageinfo, regular, no_dead_strip" 17@llvm.used = appending global [3 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @"\01L_OBJC_METH_VAR_NAME_", i32 0, i32 0), i8* bitcast (i8** @"\01L_OBJC_SELECTOR_REFERENCES_" to i8*), i8* bitcast ([2 x i32]* @"\01L_OBJC_IMAGE_INFO" to i8*)], section "llvm.metadata" 18 19define void @test(i8* %x) uwtable ssp { 20entry: 21 br label %for.body 22 23for.body: ; preds = %for.body, %entry 24 %i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ] 25 %0 = load i8*, i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8, !invariant.load !0 26 %call = tail call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*)*)(i8* %x, i8* %0) 27 %inc = add i32 %i.01, 1 28 %exitcond = icmp eq i32 %inc, 10000 29 br i1 %exitcond, label %for.end, label %for.body 30 31for.end: ; preds = %for.body 32 ret void 33} 34 35declare i8* @objc_msgSend(i8*, i8*, ...) nonlazybind 36 37define void @test_multi_def(i64* dereferenceable(8) %x1, 38 i64* dereferenceable(8) %x2, 39 i128* %y, i64 %count) nounwind { 40entry: 41 br label %for.body 42 43for.check: 44 %inc = add nsw i64 %i, 1 45 %done = icmp sge i64 %inc, %count 46 br i1 %done, label %exit, label %for.body 47 48for.body: 49 %i = phi i64 [ 0, %entry ], [ %inc, %for.check ] 50 %x1_load = load i64, i64* %x1, align 8, !invariant.load !0 51 %x1_zext = zext i64 %x1_load to i128 52 %x2_load = load i64, i64* %x2, align 8, !invariant.load !0 53 %x2_zext = zext i64 %x2_load to i128 54 %x_prod = mul i128 %x1_zext, %x2_zext 55 %y_elem = getelementptr inbounds i128, i128* %y, i64 %i 56 %y_load = load i128, i128* %y_elem, align 8 57 %y_plus = add i128 %x_prod, %y_load 58 store i128 %y_plus, i128* %y_elem, align 8 59 br label %for.check 60 61exit: 62 ret void 63} 64 65define void @test_div_def(i32* dereferenceable(8) %x1, 66 i32* dereferenceable(8) %x2, 67 i32* %y, i32 %count) nounwind { 68entry: 69 br label %for.body 70 71for.check: 72 %inc = add nsw i32 %i, 1 73 %done = icmp sge i32 %inc, %count 74 br i1 %done, label %exit, label %for.body 75 76for.body: 77 %i = phi i32 [ 0, %entry ], [ %inc, %for.check ] 78 %x1_load = load i32, i32* %x1, align 8, !invariant.load !0 79 %x2_load = load i32, i32* %x2, align 8, !invariant.load !0 80 %x_quot = udiv i32 %x1_load, %x2_load 81 %y_elem = getelementptr inbounds i32, i32* %y, i32 %i 82 %y_load = load i32, i32* %y_elem, align 8 83 %y_plus = add i32 %x_quot, %y_load 84 store i32 %y_plus, i32* %y_elem, align 8 85 br label %for.check 86 87exit: 88 ret void 89} 90 91!0 = !{} 92