[all-commits] [llvm/llvm-project] 49f751: [DivRemPairs] Freeze operands if they can be undef...
Juneyoung Lee via All-commits
all-commits at lists.llvm.org
Tue Mar 24 11:46:20 PDT 2020
Branch: refs/heads/master
Home: https://github.com/llvm/llvm-project
Commit: 49f75132bcdfcbc23010252e04e43fe0278ae1e7
https://github.com/llvm/llvm-project/commit/49f75132bcdfcbc23010252e04e43fe0278ae1e7
Author: Juneyoung Lee <aqjune at gmail.com>
Date: 2020-03-25 (Wed, 25 Mar 2020)
Changed paths:
M llvm/lib/Transforms/Scalar/DivRemPairs.cpp
M llvm/test/Transforms/DivRemPairs/PowerPC/div-expanded-rem-pair.ll
M llvm/test/Transforms/DivRemPairs/PowerPC/div-rem-pairs.ll
M llvm/test/Transforms/DivRemPairs/X86/div-rem-pairs.ll
Log Message:
-----------
[DivRemPairs] Freeze operands if they can be undef values
Summary:
DivRemPairs is unsound with respect to undef values.
```
// bb1:
// %rem = srem %x, %y
// bb2:
// %div = sdiv %x, %y
// -->
// bb1:
// %div = sdiv %x, %y
// %mul = mul %div, %y
// %rem = sub %x, %mul
```
If X can be undef, X should be frozen first.
For example, let's assume that Y = 1 & X = undef:
```
%div = sdiv undef, 1 // %div = undef
%rem = srem undef, 1 // %rem = 0
=>
%div = sdiv undef, 1 // %div = undef
%mul = mul %div, 1 // %mul = undef
%rem = sub %x, %mul // %rem = undef - undef = undef
```
http://volta.cs.utah.edu:8080/z/m7Xrx5
Same for Y. If X = 1 and Y = (undef | 1), %rem in src is either 1 or 0,
but %rem in tgt can be one of many integer values.
This resolves https://bugs.llvm.org/show_bug.cgi?id=42619 .
This miscompilation disappears if undef value is removed, but it may take a while.
DivRemPair happens pretty late during the optimization pipeline, so this optimization seemed as a good candidate to fix without major regression using freeze than other broken optimizations.
Reviewers: spatel, lebedev.ri, george.burgess.iv
Reviewed By: spatel
Subscribers: wuzish, regehr, nlopes, nemanjai, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D76483
More information about the All-commits
mailing list