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 37540 - [NewGVN] Simplification based on metadata/attributes not available on all members of a congruence class causes miscompiles
Summary: [NewGVN] Simplification based on metadata/attributes not available on all mem...
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Scalar Optimizations (show other bugs)
Version: trunk
Hardware: All All
: P normal
Assignee: Florian Hahn
URL:
Keywords:
: 37660 38214 38260 38304 (view as bug list)
Depends on:
Blocks: 30995
  Show dependency tree
 
Reported: 2018-05-21 06:40 PDT by Nikita Popov
Modified: 2018-08-17 12:23 PDT (History)
6 users (show)

See Also:
Fixed By Commit(s): r340031


Attachments
IR case from PR37660, where nsw causes miscompile (2.37 KB, text/plain)
2018-07-28 09:05 PDT, Florian Hahn
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nikita Popov 2018-05-21 06:40:19 PDT
NewGVN optimizes:

define i1 @test({}** %arg, i1 %arg2) {
    br i1 %arg2, label %bb1, label %bb2

bb1:
    %load1 = load {}*, {}** %arg
    %cmp1 = icmp eq {}* %load1, null
    ret i1 %cmp1

bb2:
    %load2 = load {}*, {}** %arg, !nonnull !1
    %cmp2 = icmp eq {}* %load2, null
    ret i1 %cmp2
}

!1 = !{}

into:

define i1 @test({}** %arg, i1 %arg2) {
  br i1 %arg2, label %bb1, label %bb2

bb1:                                              ; preds = %0
  ret i1 false

bb2:                                              ; preds = %0
  ret i1 false
}

The reason is that %load1 and %load2 are found congruent with %load2 chosen as leader. Thus %cmp1 in bb1 calls SimplifyCmp with icmp eq {}* %load2, null, which is simplified to i1 false based on the !nonnull metadata of %load2. However, this metadata is not applicable in this branch.

This bug prevents bootstrapping of rustc under newgvn.
Comment 1 Florian Hahn 2018-05-21 07:55:08 PDT
Proposed simple fix https://reviews.llvm.org/D47143
Comment 2 Florian Hahn 2018-07-28 09:02:33 PDT
PR37660 covers a related case, where we have `shl i64 %1, 32` and `shl nsw i64 %1, 32` in a congruence class and we later simplify based on nsw, which does not hold for all members.

Eli also indicated at https://reviews.llvm.org/D47143 that it would be good to fix those issues there too.
Comment 3 Florian Hahn 2018-07-28 09:03:59 PDT
*** Bug 37660 has been marked as a duplicate of this bug. ***
Comment 4 Florian Hahn 2018-07-28 09:05:00 PDT
Created attachment 20613 [details]
IR case from PR37660, where nsw causes miscompile
Comment 5 Florian Hahn 2018-08-14 07:38:09 PDT
*** Bug 38260 has been marked as a duplicate of this bug. ***
Comment 6 Florian Hahn 2018-08-14 07:39:37 PDT
*** Bug 38214 has been marked as a duplicate of this bug. ***
Comment 7 Florian Hahn 2018-08-14 07:43:51 PDT
*** Bug 38304 has been marked as a duplicate of this bug. ***
Comment 8 hiraditya 2018-08-17 12:23:14 PDT
Thanks Florian for fixing this!