[Bug tree-optimization/30911] VRP fails to eliminate range checks in Ada code
rguenth at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Thu Feb 22 17:04:00 GMT 2007
------- Comment #4 from rguenth at gcc dot gnu dot org 2007-02-22 17:04 -------
Can you walk me through some of the checks and why they can be removed? I see
(.004.gimple dump):
source = source_first;
target = target_first;
source_last.0 = (js__TsB) source_last;
source_first.1 = (js__TsB) source_first;
if (source_last.0 < source_first.1)
{
if (target_first == 10)
{
__gnat_rcheck_04 ("join_equal.adb", 13);
}
else
{
}
if (target_first == 128)
{
__gnat_rcheck_12 ("join_equal.adb", 15);
iftmp.2 = target_first;
}
else
{
iftmp.2 = target_first;
}
iftmp.3 = iftmp.2;
iftmp.4 = (js__TtB) iftmp.3;
if (iftmp.4 <= 10)
{
goto <D1039>;
}
else
{
}
iftmp.4 = (js__TtB) iftmp.3;
if (iftmp.4 > 21)
{
goto <D1039>;
}
else
{
goto <D1040>;
}
<D1039>:;
__gnat_rcheck_12 ("join_equal.adb", 15);
<D1040>:;
if (target_first == 128)
{
__gnat_rcheck_12 ("join_equal.adb", 15);
iftmp.5 = target_first;
}
else
{
iftmp.5 = target_first;
}
iftmp.6 = iftmp.5;
iftmp.7 = (js__TtB) iftmp.6;
D.1047 = iftmp.7 + -1;
target_last = (j__target_type___XDLU_10__20) D.1047;
goto <D1016>;
I assume all of the above is gimplified from just
if Source_Last < Source_First then
if Target_First = Target_Type'First then
raise Constraint_Error;
end if;
Target_Last := Target_Type'Pred (Target_First);
return;
? So in essence VRP should somehow be able to see that
Target_Type'Pred (Target_First) cannot be out of bounds because Target_First
is not Target_Type'First, correct? But given the gimplified form above
we also need to prove Target_First is not 128 (where does that come from?
It looks like __gnat_rcheck_12 is not a noreturn function?). We also
need to prove that (js__TtB) Target_First is > 10 (that looks doable from
the != 10 range we can extract from the first range check). But where
does the check against 21 come from? The 2nd check for 128 looks redundant
and indeed we remove it in VRP1.
I need to look closer at what js__TtB actually is looking like, but this
is at least a useful testcase.
Thanks.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30911
More information about the Gcc-bugs
mailing list