Skip to content

Stop turning transmutes into discriminant reads in mir-opt #111568

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
May 17, 2023

Conversation

scottmcm
Copy link
Member

Partially reverts #109612, as after #109993 these aren't actually equivalent any more, and I'm no longer confident this was ever an improvement in the first place.

Having this "simplification" meant that similar-looking code actually did somewhat different things. For example,

pub unsafe fn demo1(x: std::cmp::Ordering) -> u8 {
    std::mem::transmute(x)
}
pub unsafe fn demo2(x: std::cmp::Ordering) -> i8 {
    std::mem::transmute(x)
}

in nightly today is generating https://rust.godbolt.org/z/dPK58zW18

define noundef i8 @_ZN7example5demo117h341ef313673d2ee6E(i8 noundef %x) unnamed_addr #0 {
  %0 = icmp uge i8 %x, -1
  %1 = icmp ule i8 %x, 1
  %2 = or i1 %0, %1
  call void @llvm.assume(i1 %2)
  ret i8 %x
}

define noundef i8 @_ZN7example5demo217h5ad29f361a3f5700E(i8 noundef %0) unnamed_addr #0 {
  %x = alloca i8, align 1
  store i8 %0, ptr %x, align 1
  %1 = load i8, ptr %x, align 1, !range !2, !noundef !3
  ret i8 %1
}

Which feels too different when the original code is essentially identical.


Aside: that example is different after optimizations too:

define noundef i8 @_ZN7example5demo117h341ef313673d2ee6E(i8 noundef returned %x) unnamed_addr #0 {
  %0 = add i8 %x, 1
  %1 = icmp ult i8 %0, 3
  tail call void @llvm.assume(i1 %1)
  ret i8 %x
}

define noundef i8 @_ZN7example5demo217h5ad29f361a3f5700E(i8 noundef returned %0) unnamed_addr #1 {
  ret i8 %0
}

so turning the Transmute into a Discriminant was arguably just making things worse, so leaving it alone instead -- and thus having less code in rustc -- seems clearly better.

Partially reverts 109612, as after 109993 these aren't actually equivalent any more, and I'm no longer confident this was ever an improvement in the first place.
@rustbot
Copy link
Collaborator

rustbot commented May 14, 2023

r? @cjgillot

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 14, 2023
@rustbot
Copy link
Collaborator

rustbot commented May 14, 2023

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@WaffleLapkin
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented May 16, 2023

📌 Commit 363c202 has been approved by WaffleLapkin

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 16, 2023
@bors
Copy link
Collaborator

bors commented May 17, 2023

⌛ Testing commit 363c202 with merge e9e1bbc...

@bors
Copy link
Collaborator

bors commented May 17, 2023

☀️ Test successful - checks-actions
Approved by: WaffleLapkin
Pushing e9e1bbc to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 17, 2023
@bors bors merged commit e9e1bbc into rust-lang:master May 17, 2023
@rustbot rustbot added this to the 1.71.0 milestone May 17, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e9e1bbc): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.7% [-4.7%, -4.7%] 1
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 642.109s -> 642.487s (0.06%)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants