[LLVMbugs] [Bug 8866] New: Scev does not get max if hidden by sext. Canonicalization problem?
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Mon Dec 27 16:57:16 PST 2010
http://llvm.org/bugs/show_bug.cgi?id=8866
Summary: Scev does not get max if hidden by sext.
Canonicalization problem?
Product: libraries
Version: trunk
Platform: PC
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P
Component: Scalar Optimizations
AssignedTo: unassignedbugs at nondot.org
ReportedBy: grosser at fim.uni-passau.de
CC: llvmbugs at cs.uiuc.edu
Hi,
I just tried to "opt -scalar-evolution -analyze" on this:
define i64 @make_positive(i64 %a) nounwind readnone {
entry:
%is_a_nonnegative = icmp slt i64 %a, 0
%max = select i1 %is_a_nonnegative, i64 0, i64 %a
ret i64 %max
}
%max = select i1 %is_a_nonnegative, i64 0, i64 %a
--> (0 smax %a)
This one works fine and gives the right expression. As soon as a sext
obfuscates
this expression, scalar evolution does not work any more:
define i64 @make_positive_sextend(i32 %a) nounwind readnone {
entry:
%a_ext = sext i32 %a to i64
%is_a_nonnegative = icmp sgt i32 %a, -1
%max = select i1 %is_a_nonnegative, i64 %a_ext, i64 0
ret i64 %max
}
%a_ext = sext i32 %a to i64
--> (sext i32 %a to i64)
%max = select i1 %is_a_nonnegative, i64 %a_ext, i64 0
--> %max
Any change this can be solved in scev - or maybe even better - canonicalized
such that svec works unchanged. I see those two options:
%a_ext = sext i32 %a to i64
%is_a_nonnegative = icmp sgt i64 %a_ext, -1
%max = select i1 %is_a_nonnegative, i64 %a_ext, i64 0
ret i64 %max
%is_a_nonnegative = icmp sgt i32 %a, -1
%max = select i1 %is_a_nonnegative, i32 %a, i32 0
%max_sext = sext i32 %max to i64
ret i64 %max_sext
This also blocks some further optimizations, as the non obfuscated code is
optimized to a comparison to 0:
%is_a_nonnegative = icmp slt i64 %a, 0
%max = select i1 %is_a_nonnegative, i64 0, i64 %a
ret i64 %max
Running -O3 on the test file does not change the obfuscated code at all.
Cheers
Tobi
--
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