[llvm-commits] PR12385 PATCH: Missed constant propagation in loops

Stepan Dyatkovskiy stpworld at narod.ru
Thu May 3 13:09:03 PDT 2012


Hi Dan.
Now I'm measuring compile time within the lnt and test-suite. I'll 
prepare the results soon. IMHO, the complexity should stay the same, 
since no any additional BB scans was added. I just modified the body of 
existing loops in InstCombine, in loop bodies I'm checking limited 
amount of DenseMap items it doesn't increase complexity.

Relative to GVN. I fastly looked this pass and decided to use 
InstCombine since I found it closer to current improvement. But I'll 
look at this pass again. Probably you right and it is better to use GVN.

Relative to testcases. I attached .ll testcase and the result of 
optimization. load @i is reduced here.

P.S.: And again. Today I spent some time configuring lnt since it is new 
for me. I need some time to prepare the results for you.

-Stepan.


Dan Gohman wrote:
> On May 2, 2012, at 11:09 PM, Evan Cheng<evan.cheng at apple.com>  wrote:
>>
>> Dan, can you review this? Comments?
>
> Is there anything motivating this patch other than the given
> testcase? It seems like the patch adds a disproportionate amount
> of code and complexity.
>
> Also, from the description, the algorithm sounds a lot like
> it's trying to do something very similar towhat LLVM's GVN pass does.
> Have you looked at GVN, and do you know why it is unable to optimize
> this testcase?
>
> Dan
>

-------------- next part --------------
; RUN: opt -instcombine -disable-output -stats -info-output-file - < %s | FileCheck --check-prefix=STATS %s
; RUN: opt -S -instcombine -verify-loop-info -verify-dom-info %s | FileCheck %s

;STATS: 2 instcombine - Number of insts combined

;CHECK:      ; <label>:4
;CHECK-NEXT:   br i1 false, label %5, label %6

@i = common global i32 0, align 4

define void @bar() nounwind uwtable {
  %j = alloca i32, align 4
  store i32 0, i32* %j, align 4
  store i32 0, i32* @i, align 4
  br label %1

; <label>:1                                       ; preds = %9, %0
  %2 = load i32* %j, align 4
  %3 = icmp slt i32 %2, 10000
  br i1 %3, label %4, label %12

; <label>:4                                       ; preds = %1
  %5 = load i32* @i, align 4
  %6 = icmp ne i32 %5, 0
  br i1 %6, label %7, label %8

; <label>:7                                       ; preds = %4
  call void @foo()
  br label %8

; <label>:8                                       ; preds = %7, %4
  br label %9

; <label>:9                                       ; preds = %8
  %10 = load i32* %j, align 4
  %11 = add nsw i32 %10, 1
  store i32 %11, i32* %j, align 4
  br label %1

; <label>:12                                      ; preds = %1
  ret void
}

declare void @foo()
-------------- next part --------------
; ModuleID = '/home/stepan/??????? ????/2012-04-18-StLdTracking-Resolved.ll'

@i = common global i32 0, align 4

define void @bar() nounwind uwtable {
  %j = alloca i32, align 4
  store i32 0, i32* %j, align 4
  store i32 0, i32* @i, align 4
  br label %1

; <label>:1                                       ; preds = %7, %0
  %2 = load i32* %j, align 4
  %3 = icmp slt i32 %2, 10000
  br i1 %3, label %4, label %10

; <label>:4                                       ; preds = %1
  br i1 false, label %5, label %6

; <label>:5                                       ; preds = %4
  br label %6

; <label>:6                                       ; preds = %5, %4
  br label %7

; <label>:7                                       ; preds = %6
  %8 = load i32* %j, align 4
  %9 = add nsw i32 %8, 1
  store i32 %9, i32* %j, align 4
  br label %1

; <label>:10                                      ; preds = %1
  ret void
}

declare void @foo()


More information about the llvm-commits mailing list