Simplify GEP's and Load's in InlineCost

sschiffli at gmail.com sschiffli at gmail.com
Wed Sep 18 08:39:28 PDT 2013


Here is the example, just pasted as plain-text

; ModuleID = 'test.ll'
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S32"
target triple = "i686-pc-win32"

%struct.SS = type { i32 }

@a = internal constant %struct.SS { i32 1 }, align 4

; Function Attrs: nounwind
define i32 @_Z3fooRK2SS(%struct.SS* %s) #0 {
entry:
  %x1 = alloca i32, align 4
  %x4 = alloca i32, align 4
  %x8 = alloca i32, align 4
  %x12 = alloca i32, align 4
  %x16 = alloca i32, align 4
  %x20 = alloca i32, align 4
  %x = getelementptr inbounds %struct.SS* %s, i32 0, i32 0
  %0 = load i32* %x, align 4
  switch i32 %0, label %sw.default [
    i32 0, label %sw.bb
    i32 1, label %sw.bb3
    i32 2, label %sw.bb7
    i32 3, label %sw.bb11
    i32 4, label %sw.bb15
    i32 5, label %sw.bb19
  ]

sw.bb:                                            ; preds = %entry
  %1 = load volatile i32* %x1, align 4
  %inc = add nsw i32 %1, 1
  store volatile i32 %inc, i32* %x1, align 4
  %2 = load volatile i32* %x1, align 4
  %inc2 = add nsw i32 %2, 1
  store volatile i32 %inc2, i32* %x1, align 4
  %3 = load volatile i32* %x1, align 4
  br label %return

sw.bb3:                                           ; preds = %entry
  %4 = load volatile i32* %x4, align 4
  %inc5 = add nsw i32 %4, 1
  store volatile i32 %inc5, i32* %x4, align 4
  %5 = load volatile i32* %x4, align 4
  %inc6 = add nsw i32 %5, 1
  store volatile i32 %inc6, i32* %x4, align 4
  %6 = load volatile i32* %x4, align 4
  br label %return

sw.bb7:                                           ; preds = %entry
  %7 = load volatile i32* %x8, align 4
  %inc9 = add nsw i32 %7, 1
  store volatile i32 %inc9, i32* %x8, align 4
  %8 = load volatile i32* %x8, align 4
  %inc10 = add nsw i32 %8, 1
  store volatile i32 %inc10, i32* %x8, align 4
  %9 = load volatile i32* %x8, align 4
  br label %return

sw.bb11:                                          ; preds = %entry
  %10 = load volatile i32* %x12, align 4
  %inc13 = add nsw i32 %10, 1
  store volatile i32 %inc13, i32* %x12, align 4
  %11 = load volatile i32* %x12, align 4
  %inc14 = add nsw i32 %11, 1
  store volatile i32 %inc14, i32* %x12, align 4
  %12 = load volatile i32* %x12, align 4
  br label %return

sw.bb15:                                          ; preds = %entry
  %13 = load volatile i32* %x16, align 4
  %inc17 = add nsw i32 %13, 1
  store volatile i32 %inc17, i32* %x16, align 4
  %14 = load volatile i32* %x16, align 4
  %inc18 = add nsw i32 %14, 1
  store volatile i32 %inc18, i32* %x16, align 4
  %15 = load volatile i32* %x16, align 4
  br label %return

sw.bb19:                                          ; preds = %entry
  %16 = load volatile i32* %x20, align 4
  %inc21 = add nsw i32 %16, 1
  store volatile i32 %inc21, i32* %x20, align 4
  %17 = load volatile i32* %x20, align 4
  %inc22 = add nsw i32 %17, 1
  store volatile i32 %inc22, i32* %x20, align 4
  %18 = load volatile i32* %x20, align 4
  br label %return

sw.default:                                       ; preds = %entry
  br label %return

return:                                           ; preds = %sw.default, %sw.bb19, %sw.bb15, %sw.bb11, %sw.bb7, %sw.bb3, %sw.bb
  %retval.0 = phi i32 [ -1, %sw.default ], [ %18, %sw.bb19 ], [ %15, %sw.bb15 ], [ %12, %sw.bb11 ], [ %9, %sw.bb7 ], [ %6, %sw.bb3 ], [ %3, %sw.bb ]
  ret i32 %retval.0
}

; Function Attrs: nounwind
define i32 @main() #0 {
entry:
  %call = call i32 @_Z3fooRK2SS(%struct.SS* @a)
  ret i32 %call
}

attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }


On Sep 17, 2013, at 9:48 AM, llvm-commits-request at cs.uiuc.edu wrote:

> Hi Stephen,
> 
> On 17/09/13 00:50, Stephen Schiffli wrote:
>> Attached is a patch which attempts to simplify loads and GEPs when calculating
>> inline cost.  Also attached is an example of the situation I ran into which
>> motivated this work.
> 
> the example seems to have gotten lost.
> 
> Ciao, Duncan.
> 
>> 
>> In my specific case, I ended up with many constant structures and some functions
>> which take these constants as parameters.  These function do a switch based on
>> some piece of date in the structure.  Currently when calculating cost we must
>> add the cost of all the blocks since it can't determine the destination of the
>> switch.  However if we simplify the loads and GEPs we can figure out the
>> destination block of the switch and thus only count a single block in the switch.
>> 
>> I am hoping to get feedback on whether or not what I'm trying to do is valid.
>> 
>> Thanks,
>> -Stephen
>> 
>> 
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list