Home | History | Annotate | Download | only in InstMerge
      1 ; ModuleID = 'bug.c'
      2 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
      3 target triple = "x86_64-unknown-linux-gnu"
      4 
      5 ; RUN: opt -O2 -S < %s | FileCheck %s
      6 
      7 ; CHECK_LABEL: main
      8 ; CHECK: if.end
      9 ; CHECK: store
     10 ; CHECK: memset
     11 ; CHECK: if.then
     12 ; CHECK: store
     13 ; CHECK: memset
     14 
     15 @d = common global i32 0, align 4
     16 @b = common global i32 0, align 4
     17 @f = common global [1 x [3 x i8]] zeroinitializer, align 1
     18 @e = common global i32 0, align 4
     19 @c = common global i32 0, align 4
     20 @a = common global i32 0, align 4
     21 
     22 ; Function Attrs: nounwind uwtable
     23 define void @fn1() {
     24 entry:
     25   store i32 0, i32* @d, align 4
     26   br label %for.cond
     27 
     28 for.cond:                                         ; preds = %for.inc8, %entry
     29   %0 = load i32, i32* @d, align 4
     30   %cmp = icmp slt i32 %0, 2
     31   br i1 %cmp, label %for.body, label %for.end10
     32 
     33 for.body:                                         ; preds = %for.cond
     34   %1 = load i32, i32* @d, align 4
     35   %idxprom = sext i32 %1 to i64
     36   %2 = load i32, i32* @b, align 4
     37   %idxprom1 = sext i32 %2 to i64
     38   %arrayidx = getelementptr inbounds [1 x [3 x i8]], [1 x [3 x i8]]* @f, i32 0, i64 %idxprom1
     39   %arrayidx2 = getelementptr inbounds [3 x i8], [3 x i8]* %arrayidx, i32 0, i64 %idxprom
     40   store i8 0, i8* %arrayidx2, align 1
     41   store i32 0, i32* @e, align 4
     42   br label %for.cond3
     43 
     44 for.cond3:                                        ; preds = %for.inc, %for.body
     45   %3 = load i32, i32* @e, align 4
     46   %cmp4 = icmp slt i32 %3, 3
     47   br i1 %cmp4, label %for.body5, label %for.end
     48 
     49 for.body5:                                        ; preds = %for.cond3
     50   %4 = load i32, i32* @c, align 4
     51   %tobool = icmp ne i32 %4, 0
     52   br i1 %tobool, label %if.then, label %if.end
     53 
     54 if.then:                                          ; preds = %for.body5
     55   %5 = load i32, i32* @a, align 4
     56   %dec = add nsw i32 %5, -1
     57   store i32 %dec, i32* @a, align 4
     58   br label %if.end
     59 
     60 if.end:                                           ; preds = %if.then, %for.body5
     61   %6 = load i32, i32* @e, align 4
     62   %idxprom6 = sext i32 %6 to i64
     63   %arrayidx7 = getelementptr inbounds [3 x i8], [3 x i8]* getelementptr inbounds ([1 x [3 x i8]], [1 x [3 x i8]]* @f, i32 0, i64 0), i32 0, i64 %idxprom6
     64   store i8 1, i8* %arrayidx7, align 1
     65   br label %for.inc
     66 
     67 for.inc:                                          ; preds = %if.end
     68   %7 = load i32, i32* @e, align 4
     69   %inc = add nsw i32 %7, 1
     70   store i32 %inc, i32* @e, align 4
     71   br label %for.cond3
     72 
     73 for.end:                                          ; preds = %for.cond3
     74   br label %for.inc8
     75 
     76 for.inc8:                                         ; preds = %for.end
     77   %8 = load i32, i32* @d, align 4
     78   %inc9 = add nsw i32 %8, 1
     79   store i32 %inc9, i32* @d, align 4
     80   br label %for.cond
     81 
     82 for.end10:                                        ; preds = %for.cond
     83   ret void
     84 }
     85 
     86 ; Function Attrs: nounwind uwtable
     87 define i32 @main() {
     88 entry:
     89   %retval = alloca i32, align 4
     90   store i32 0, i32* %retval
     91   call void @fn1()
     92   %0 = load i8, i8* getelementptr inbounds ([1 x [3 x i8]], [1 x [3 x i8]]* @f, i32 0, i64 0, i64 1), align 1
     93   %conv = sext i8 %0 to i32
     94   %cmp = icmp ne i32 %conv, 1
     95   br i1 %cmp, label %if.then, label %if.end
     96 
     97 if.then:                                          ; preds = %entry
     98   call void @abort()
     99   unreachable
    100 
    101 if.end:                                           ; preds = %entry
    102   ret i32 0
    103 }
    104 
    105 ; Function Attrs: noreturn nounwind
    106 declare void @abort()
    107