1; RUN: opt -gvn-hoist -newgvn -gvn-hoist -S < %s | FileCheck %s 2; Test to demonstrate that newgvn creates opportunities for 3; more gvn-hoist when sibling branches contain identical expressions. 4 5target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 6target triple = "x86_64-unknown-linux-gnu" 7 8; Check that all "or" expressions are hoisted. 9; CHECK-LABEL: @encode 10; CHECK: or i32 11; CHECK-NOT: or i32 12 13define i8* @encode(i8* %p, i32 %v) { 14entry: 15 %p.addr = alloca i8*, align 8 16 %v.addr = alloca i32, align 4 17 store i8* %p, i8** %p.addr, align 8 18 store i32 %v, i32* %v.addr, align 4 19 %0 = load i32, i32* %v.addr, align 4 20 %cmp = icmp ult i32 %0, 23 21 br i1 %cmp, label %if.then, label %if.else 22 23if.then: ; preds = %entry 24 %1 = load i32, i32* %v.addr, align 4 25 %or = or i32 %1, 128 26 %conv = trunc i32 %or to i8 27 %2 = load i8*, i8** %p.addr, align 8 28 %incdec.ptr = getelementptr inbounds i8, i8* %2, i32 1 29 store i8* %incdec.ptr, i8** %p.addr, align 8 30 store i8 %conv, i8* %2, align 1 31 br label %if.end15 32 33if.else: ; preds = %entry 34 %3 = load i32, i32* %v.addr, align 4 35 %cmp1 = icmp ult i32 %3, 42 36 br i1 %cmp1, label %if.then3, label %if.else9 37 38if.then3: ; preds = %if.else 39 %4 = load i32, i32* %v.addr, align 4 40 %or4 = or i32 %4, 128 41 %conv5 = trunc i32 %or4 to i8 42 %5 = load i8*, i8** %p.addr, align 8 43 %incdec.ptr6 = getelementptr inbounds i8, i8* %5, i32 1 44 store i8* %incdec.ptr6, i8** %p.addr, align 8 45 store i8 %conv5, i8* %5, align 1 46 %6 = load i32, i32* %v.addr, align 4 47 %conv7 = trunc i32 %6 to i8 48 %7 = load i8*, i8** %p.addr, align 8 49 %incdec.ptr8 = getelementptr inbounds i8, i8* %7, i32 1 50 store i8* %incdec.ptr8, i8** %p.addr, align 8 51 store i8 %conv7, i8* %7, align 1 52 br label %if.end 53 54if.else9: ; preds = %if.else 55 %8 = load i32, i32* %v.addr, align 4 56 %or10 = or i32 %8, 128 57 %conv11 = trunc i32 %or10 to i8 58 %9 = load i8*, i8** %p.addr, align 8 59 %incdec.ptr12 = getelementptr inbounds i8, i8* %9, i32 1 60 store i8* %incdec.ptr12, i8** %p.addr, align 8 61 store i8 %conv11, i8* %9, align 1 62 %10 = load i32, i32* %v.addr, align 4 63 %shr = lshr i32 %10, 7 64 %conv13 = trunc i32 %shr to i8 65 %11 = load i8*, i8** %p.addr, align 8 66 %incdec.ptr14 = getelementptr inbounds i8, i8* %11, i32 1 67 store i8* %incdec.ptr14, i8** %p.addr, align 8 68 store i8 %conv13, i8* %11, align 1 69 br label %if.end 70 71if.end: ; preds = %if.else9, %if.then3 72 br label %if.end15 73 74if.end15: ; preds = %if.end, %if.then 75 %12 = load i8*, i8** %p.addr, align 8 76 ret i8* %12 77} 78