LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 42209 - Instsimplify: uadd_overflow(X, undef) is not undef
Summary: Instsimplify: uadd_overflow(X, undef) is not undef
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Scalar Optimizations (show other bugs)
Version: trunk
Hardware: All All
: P normal
Assignee: Roman Lebedev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-09 12:15 PDT by Nuno Lopes
Modified: 2019-09-01 04:12 PDT (History)
7 users (show)

See Also:
Fixed By Commit(s): 363522


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nuno Lopes 2019-06-09 12:15:08 PDT
test/Transforms/InstSimplify/call.ll contains a few incorrect transformations when undef is involved.

For example, when %v is zero, there's no overflow, so can't fold this to undef:

define {i8, i1} @test_uadd3(i8 %v) {
%0:
  %result = uadd_overflow i8 %v, undef
  ret {i8, i1} %result
}
=>
define {i8, i1} @test_uadd3(i8 %v) {
%0:
  ret {i8, i1} undef
}
Transformation doesn't verify!
ERROR: Value mismatch

Example:
i8 %v = #x00 (0)

Source:
{i8, i1} %result = { ?, #x0 }

Target:
Source value: { ?, #x0 }
Target value: { #x00, #x1 }
Comment 1 Nikita Popov 2019-06-09 14:18:42 PDT
https://reviews.llvm.org/D63065
Comment 2 Roman Lebedev 2019-06-16 09:27:16 PDT
(In reply to Nikita Popov from comment #1)
> https://reviews.llvm.org/D63065

Yep, undef is uh, mindmelting.

@Nuno - to summarize, and check myself - am i correct that we
can fold the entire `{u,s}{add,sub}.with.overflow(%a, undef)` to `{undef, 0}`?

To me, we can as per https://github.com/AliveToolkit/alive2/issues/71#issuecomment-502461113
But is that checking what i think it is checking?
If not, alive is missing `insertvalue` i guess?
Comment 3 Nuno Lopes 2019-06-16 12:22:13 PDT
(In reply to Roman Lebedev from comment #2)
> (In reply to Nikita Popov from comment #1)
> > https://reviews.llvm.org/D63065
> 
> Yep, undef is uh, mindmelting.
> 
> @Nuno - to summarize, and check myself - am i correct that we
> can fold the entire `{u,s}{add,sub}.with.overflow(%a, undef)` to `{undef,
> 0}`?
> 
> To me, we can as per
> https://github.com/AliveToolkit/alive2/issues/71#issuecomment-502461113
> But is that checking what i think it is checking?
> If not, alive is missing `insertvalue` i guess?

It is proving exactly what you want; the transformation you mention is correct per the `undef` semantics. You can fold to `{undef, 0}`.
Comment 4 Roman Lebedev 2019-06-16 13:40:23 PDT
I didn't check with alive-tv, so if this suddenly is still incorrect, do CC me in the new bug (: