[LLVMbugs] [Bug 1768] New: correlatedexpression optimization needs 2 passes, and misses optimization due to function parameter order
bugzilla-daemon at cs.uiuc.edu
bugzilla-daemon at cs.uiuc.edu
Sun Nov 4 02:29:36 PST 2007
http://llvm.org/bugs/show_bug.cgi?id=1768
Summary: correlatedexpression optimization needs 2 passes, and
misses optimization due to function parameter order
Product: new-bugs
Version: unspecified
Platform: PC
OS/Version: Linux
Status: NEW
Severity: minor
Priority: P2
Component: new bugs
AssignedTo: unassignedbugs at nondot.org
ReportedBy: edwintorok at gmail.com
CC: llvmbugs at cs.uiuc.edu
Consider these 2 functions opt_fail and opt_ok, where only the order of the
parameters is different.
In opt_fail's case llvm doesn't recognize the optimization opportunity in
cond_true, while it recognizes it in opt_ok.
Also it takes an additional run of opt to actually optimize out the sub
instruction in opt_ok.
I think opt should optimize out the sub in one pass for opt_ok.
For opt_fail: if i==j, it should recognize that j==i too (unless this would
cause infinite loops).
; ModuleID = 'foo.bc'
target datalayout =
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
target triple = "x86_64-unknown-linux-gnu"
define i32 @opt_fail(i32 %i, i32 %j) {
entry:
%tmp7 = icmp eq i32 %i, %j ; <i1> [#uses=1]
br i1 %tmp7, label %cond_true, label %UnifiedReturnBlock1
cond_true: ; preds = %entry
%tmp11 = sub i32 %i, %j ; <i32> [#uses=1]
ret i32 %tmp11
UnifiedReturnBlock1: ; preds = %entry
ret i32 5
}
define i32 @opt_ok(i32 %j, i32 %i) {
entry:
%tmp7 = icmp eq i32 %i, %j ; <i1> [#uses=1]
br i1 %tmp7, label %cond_true, label %UnifiedReturnBlock1
cond_true: ; preds = %entry
%tmp11 = sub i32 %i, %j ; <i32> [#uses=1]
ret i32 %tmp11
UnifiedReturnBlock1: ; preds = %entry
ret i32 5
}
$ opt -cee -std-compile-opts -debug-only=cee foo.bc -o foo2.bc -f
RegionInfo for basic block: cond_true
ValueInfo for: i32 %i
Bounds = [-1,-1 )
is == i32 %j
ValueInfo for: i32 %j
Bounds = [-1,-1 )
is == i32 %j
ValueInfo for: i1 %tmp7
Bounds = [-1,0 )
Replacement = i1 true
is == i1 true
RegionInfo for basic block: UnifiedReturnBlock
ValueInfo for: i32 %i
Bounds = [-1,-1 )
is != i32 %j
ValueInfo for: i32 %j
Bounds = [-1,-1 )
is != i32 %i
ValueInfo for: i1 %tmp7
Bounds = [0,-1 )
Replacement = i1 false
is == i1 false
RegionInfo for basic block: cond_true
ValueInfo for: i1 %tmp7
Bounds = [-1,0 )
Replacement = i1 true
is == i1 true
ValueInfo for: i32 %j
Bounds = [-1,-1 )
is == i32 %j
ValueInfo for: i32 %i
Bounds = [-1,-1 )
Replacement = i32 %j
is == i32 %j
In Inst: %tmp11 = sub i32 %i, %j ; <i32> [#uses=1]
Replacing operand #0 with i32 %j
RegionInfo for basic block: UnifiedReturnBlock
ValueInfo for: i1 %tmp7
Bounds = [0,-1 )
Replacement = i1 false
is == i1 false
ValueInfo for: i32 %j
Bounds = [-1,-1 )
is != i32 %i
ValueInfo for: i32 %i
Bounds = [-1,-1 )
is != i32 %j
; ModuleID = 'foo2.bc'
target datalayout =
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
target triple = "x86_64-unknown-linux-gnu"
define i32 @opt_fail(i32 %i, i32 %j) {
entry:
%tmp7 = icmp eq i32 %i, %j ; <i1> [#uses=1]
br i1 %tmp7, label %cond_true, label %UnifiedReturnBlock
cond_true: ; preds = %entry
%tmp11 = sub i32 %i, %j ; <i32> [#uses=1]
ret i32 %tmp11
UnifiedReturnBlock: ; preds = %entry
ret i32 5
}
define i32 @opt_ok(i32 %j, i32 %i) {
entry:
%tmp7 = icmp eq i32 %i, %j ; <i1> [#uses=1]
br i1 %tmp7, label %cond_true, label %UnifiedReturnBlock
cond_true: ; preds = %entry
%tmp11 = sub i32 %j, %j ; <i32> [#uses=1]
ret i32 %tmp11
UnifiedReturnBlock: ; preds = %entry
ret i32 5
}
$ opt -std-compile-opts foo2.bc -o foo3.bc -f
ModuleID = 'foo3.bc'
target datalayout =
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
target triple = "x86_64-unknown-linux-gnu"
define i32 @opt_fail(i32 %i, i32 %j) {
entry:
%tmp7 = icmp eq i32 %i, %j ; <i1> [#uses=1]
br i1 %tmp7, label %cond_true, label %UnifiedReturnBlock1
cond_true: ; preds = %entry
%tmp11 = sub i32 %i, %j ; <i32> [#uses=1]
ret i32 %tmp11
UnifiedReturnBlock1: ; preds = %entry
ret i32 5
}
define i32 @opt_ok(i32 %j, i32 %i) {
entry:
%tmp7 = icmp eq i32 %i, %j ; <i1> [#uses=1]
%retval = select i1 %tmp7, i32 0, i32 5 ; <i32> [#uses=1]
ret i32 %retval
}
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list