Open Quuxplusone opened 9 years ago
Bugzilla Link | PR20997 |
Status | NEW |
Importance | P normal |
Reported by | John Regehr (regehr@cs.utah.edu) |
Reported on | 2014-09-18 18:28:20 -0700 |
Last modified on | 2017-08-13 22:37:50 -0700 |
Version | trunk |
Hardware | PC Linux |
CC | david.majnemer@gmail.com, llvm-bugs@lists.llvm.org, peter@pcc.me.uk, raimondas.sasnauskas@cs.rwth-aachen.de, rnk@google.com, sanjoy@playingwithpointers.com, santosh.nagarakatte@gmail.com, spatel+llvm@rotateright.com |
Fixed by commit(s) | |
Attachments | |
Blocks | |
Blocked by | |
See also | PR21412, PR20895, PR34133 |
This bug is caused by simplifycfg, arguably because isSafeToSpeculativelyExecute
assumes all add/sub operations are safe to speculate. We should examine if the binary operator has uses in it's basic block first.
This raises an interesting question: is it better to drop the nsw and speculate, or to keep it and not speculate?
Or maybe not so interesting, seems pretty clear that the cost of a branch exceeds the expected value of an nsw.
Here is an example where we are in a bit of a pickle:
define i32 @main(i32 %x0, i1 %cmp, i1 %cmp1) {
entry:
%sub = sub nsw i32 2147483647, %x0
br i1 %cmp, label %land.lhs.true, label %lor.rhs
land.lhs.true: ; preds = %entry
br i1 %cmp1, label %lor.end, label %lor.rhs
lor.rhs: ; preds = %land.lhs.true,
%entry
br label %lor.end
lor.end: ; preds = %lor.rhs,
%land.lhs.true
%phi = phi i32 [ %sub, %land.lhs.true ], [ 0, %lor.rhs ]
ret i32 %phi
}
Note there is nothing left to hoist, just branches to fold away.
Since phi poison-ness depends on *which* label it came from, %phi is poison
free.
However after running simplifycfg:
define i32 @main(i32 %x0, i1 %cmp, i1 %cmp1) {
entry:
%sub = sub nsw i32 2147483647, %x0
%cmp.not = xor i1 %cmp, true
%cmp1.not = xor i1 %cmp1, true
%brmerge = or i1 %cmp.not, %cmp1.not
%phi = select i1 %brmerge, i32 0, i32 %sub
ret i32 %phi
}
Did we just make it possible to introduce poison into the select instruction?
select's semantics are not clear at all here.
References back to the dev list discussions regarding poison and nsw:
http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-December/046152.html
http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-September/076592.html