Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[InstCombine] Miscompilation which simplifies a use of a multi-use freeze #91178

Closed
dtcxzyw opened this issue May 6, 2024 · 0 comments · Fixed by #91215
Closed

[InstCombine] Miscompilation which simplifies a use of a multi-use freeze #91178

dtcxzyw opened this issue May 6, 2024 · 0 comments · Fixed by #91215

Comments

@dtcxzyw
Copy link
Member

dtcxzyw commented May 6, 2024

Reduced test case: https://alive2.llvm.org/ce/z/_JyUGw

define i8 @func78(i1 %0, i8 %1) {
  %3 = zext i1 %0 to i8
  %4 = shl i8 %3, %1
  %5 = freeze i8 %4
  %6 = select i1 %0, i8 0, i8 %5
  %7 = call i8 @llvm.fshr.i8(i8 0, i8 %5, i8 %6)
  ret i8 %7
}
----------------------------------------
define i8 @func78(i1 %#0, i8 %#1) {
#2:
  %#3 = zext i1 %#0 to i8
  %#4 = shl i8 %#3, %#1
  %#5 = freeze i8 %#4
  %#6 = select i1 %#0, i8 0, i8 %#5
  %#7 = fshr i8 0, i8 %#5, i8 %#6
  ret i8 %#7
}
=>
define i8 @func78(i1 %#0, i8 %#1) nofree noundef willreturn memory(none) {
#2:
  %#3 = zext i1 %#0 to i8
  %#4 = shl nuw i8 %#3, %#1
  %#5 = freeze i8 %#4
  ret i8 %#5
}
Transformation doesn't verify!

ERROR: Value mismatch

Example:
i1 %#0 = #x0 (0)
i8 %#1 = #x08 (8)

Source:
i8 %#3 = #x00 (0)
i8 %#4 = poison
i8 %#5 = #x00 (0)
i8 %#6 = #x00 (0)
i8 %#7 = #x00 (0)

Target:
i8 %#3 = #x00 (0)
i8 %#4 = poison
i8 %#5 = #x9d (157, -99)
Source value: #x00 (0)
Target value: #x9d (157, -99)

Summary:
  0 correct transformations
  1 incorrect transformations
  0 failed-to-prove transformations
  0 Alive2 errors
@dtcxzyw dtcxzyw self-assigned this May 6, 2024
@dtcxzyw dtcxzyw changed the title [InstCombine] Miscompilation [InstCombine] Miscompilation which simplifies a use of a multi-use freeze May 6, 2024
dtcxzyw added a commit that referenced this issue May 8, 2024
…1215)

See the LangRef:
> All uses of a value returned by the same ‘freeze’ instruction are
guaranteed to always observe the same value, while different ‘freeze’
instructions may yield different values.

It is incorrect to replace freezes with the simplified value.

Proof:
https://alive2.llvm.org/ce/z/3Dn9Cd
https://alive2.llvm.org/ce/z/Qyh5h6

Fixes #91178
AtariDreams pushed a commit to AtariDreams/llvm-project that referenced this issue May 8, 2024
…vm#91215)

See the LangRef:
> All uses of a value returned by the same ‘freeze’ instruction are
guaranteed to always observe the same value, while different ‘freeze’
instructions may yield different values.

It is incorrect to replace freezes with the simplified value.

Proof:
https://alive2.llvm.org/ce/z/3Dn9Cd
https://alive2.llvm.org/ce/z/Qyh5h6

Fixes llvm#91178

(cherry picked from commit d085b42)

Revert "[InstSimplify] Do not simplify freeze in `simplifyWithOpReplaced` (llvm#91215)"

This reverts commit 1c2eb18d52976fef89972e89c52d2ec5ed7e4868.

[InstSimplify] Do not simplify freeze in `simplifyWithOpReplaced` (llvm#91215)

See the LangRef:
> All uses of a value returned by the same ‘freeze’ instruction are
guaranteed to always observe the same value, while different ‘freeze’
instructions may yield different values.

It is incorrect to replace freezes with the simplified value.

Proof:
https://alive2.llvm.org/ce/z/3Dn9Cd
https://alive2.llvm.org/ce/z/Qyh5h6

Fixes llvm#91178

(cherry picked from commit d085b42)
AtariDreams pushed a commit to AtariDreams/llvm-project that referenced this issue May 9, 2024
…vm#91215)

See the LangRef:
> All uses of a value returned by the same ‘freeze’ instruction are
guaranteed to always observe the same value, while different ‘freeze’
instructions may yield different values.

It is incorrect to replace freezes with the simplified value.

Proof:
https://alive2.llvm.org/ce/z/3Dn9Cd
https://alive2.llvm.org/ce/z/Qyh5h6

Fixes llvm#91178

(cherry picked from commit d085b42)

Revert "[InstSimplify] Do not simplify freeze in `simplifyWithOpReplaced` (llvm#91215)"

This reverts commit 1c2eb18d52976fef89972e89c52d2ec5ed7e4868.

[InstSimplify] Do not simplify freeze in `simplifyWithOpReplaced` (llvm#91215)

See the LangRef:
> All uses of a value returned by the same ‘freeze’ instruction are
guaranteed to always observe the same value, while different ‘freeze’
instructions may yield different values.

It is incorrect to replace freezes with the simplified value.

Proof:
https://alive2.llvm.org/ce/z/3Dn9Cd
https://alive2.llvm.org/ce/z/Qyh5h6

Fixes llvm#91178

(cherry picked from commit d085b42)
tstellar pushed a commit to AtariDreams/llvm-project that referenced this issue May 14, 2024
…vm#91215)

See the LangRef:
> All uses of a value returned by the same ‘freeze’ instruction are
guaranteed to always observe the same value, while different ‘freeze’
instructions may yield different values.

It is incorrect to replace freezes with the simplified value.

Proof:
https://alive2.llvm.org/ce/z/3Dn9Cd
https://alive2.llvm.org/ce/z/Qyh5h6

Fixes llvm#91178

(cherry picked from commit d085b42)

Revert "[InstSimplify] Do not simplify freeze in `simplifyWithOpReplaced` (llvm#91215)"

This reverts commit 1c2eb18d52976fef89972e89c52d2ec5ed7e4868.

[InstSimplify] Do not simplify freeze in `simplifyWithOpReplaced` (llvm#91215)

See the LangRef:
> All uses of a value returned by the same ‘freeze’ instruction are
guaranteed to always observe the same value, while different ‘freeze’
instructions may yield different values.

It is incorrect to replace freezes with the simplified value.

Proof:
https://alive2.llvm.org/ce/z/3Dn9Cd
https://alive2.llvm.org/ce/z/Qyh5h6

Fixes llvm#91178

(cherry picked from commit d085b42)
tstellar pushed a commit to AtariDreams/llvm-project that referenced this issue May 14, 2024
…vm#91215)

See the LangRef:
> All uses of a value returned by the same ‘freeze’ instruction are
guaranteed to always observe the same value, while different ‘freeze’
instructions may yield different values.

It is incorrect to replace freezes with the simplified value.

Proof:
https://alive2.llvm.org/ce/z/3Dn9Cd
https://alive2.llvm.org/ce/z/Qyh5h6

Fixes llvm#91178

(cherry picked from commit d085b42)

Revert "[InstSimplify] Do not simplify freeze in `simplifyWithOpReplaced` (llvm#91215)"

This reverts commit 1c2eb18d52976fef89972e89c52d2ec5ed7e4868.

[InstSimplify] Do not simplify freeze in `simplifyWithOpReplaced` (llvm#91215)

See the LangRef:
> All uses of a value returned by the same ‘freeze’ instruction are
guaranteed to always observe the same value, while different ‘freeze’
instructions may yield different values.

It is incorrect to replace freezes with the simplified value.

Proof:
https://alive2.llvm.org/ce/z/3Dn9Cd
https://alive2.llvm.org/ce/z/Qyh5h6

Fixes llvm#91178

(cherry picked from commit d085b42)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant