[llvm-bugs] [Bug 41606] New: delete dead CFG edges based on __builtin_assume

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Apr 25 12:04:17 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=41606

            Bug ID: 41606
           Summary: delete dead CFG edges based on __builtin_assume
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: richard-llvm at metafoo.co.uk
                CC: llvm-bugs at lists.llvm.org

Testcase:

struct pair { int first; bool second; };

bool mode;
int arr[8];

inline pair do_some_work() {
    if (mode) {
        int k = 0;
        for (int n = 0; n != 8; ++n)
            k += arr[n];
        return {k, mode};
    } else {
        int k = 1;
        for (int n = 0; n != 8; ++n)
            k *= arr[n];
        return {k, mode};
    }
}

int f() {
    auto res = do_some_work();
    __builtin_assume(res.second);
    return res.first;
}


Produces:

; Function Attrs: nounwind uwtable
define dso_local i32 @_Z1fv() local_unnamed_addr #0 {
  %1 = load i8, i8* @mode, align 1, !tbaa !2, !range !6
  %2 = icmp eq i8 %1, 0
  %3 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 0), align 16, !tbaa !7
  %4 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 1), align 4, !tbaa !7
  br i1 %2, label %19, label %5

5:                                                ; preds = %0
  %6 = add nsw i32 %4, %3
  %7 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 2), align 8, !tbaa !7
  %8 = add nsw i32 %6, %7
  %9 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 3), align 4, !tbaa !7
  %10 = add nsw i32 %8, %9
  %11 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 4), align 16, !tbaa !7
  %12 = add nsw i32 %10, %11
  %13 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 5), align 4, !tbaa !7
  %14 = add nsw i32 %12, %13
  %15 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 6), align 8, !tbaa !7
  %16 = add nsw i32 %14, %15
  %17 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 7), align 4, !tbaa !7
  %18 = add nsw i32 %16, %17
  br label %33

19:                                               ; preds = %0
  %20 = mul nsw i32 %4, %3
  %21 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 2), align 8, !tbaa !7
  %22 = mul nsw i32 %20, %21
  %23 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 3), align 4, !tbaa !7
  %24 = mul nsw i32 %22, %23
  %25 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 4), align 16, !tbaa !7
  %26 = mul nsw i32 %24, %25
  %27 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 5), align 4, !tbaa !7
  %28 = mul nsw i32 %26, %27
  %29 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 6), align 8, !tbaa !7
  %30 = mul nsw i32 %28, %29
  %31 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @arr, i64
0, i64 7), align 4, !tbaa !7
  %32 = mul nsw i32 %30, %31
  br label %33

33:                                               ; preds = %5, %19
  %34 = phi i32 [ %32, %19 ], [ %18, %5 ]
  %35 = icmp ne i8 %1, 0
  tail call void @llvm.assume(i1 %35)
  ret i32 %34
}


We could simplify this significantly by taking advantage of the assumption from
the llvm.assume.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190425/38ea6436/attachment.html>


More information about the llvm-bugs mailing list