The select may have been preventing a division by zero so removing it might not be safe.
Fixes PR36362.
Differential D43276
[InstCombine] Don't fold select(C, Z, binop(select(C, X, Y), W)) -> select(C, Z, binop(Y, W)) if the binop is rem or div. craig.topper on Feb 13 2018, 8:35 PM. Authored by
Details
The select may have been preventing a division by zero so removing it might not be safe. Fixes PR36362.
Diff Detail
Event TimelineComment Actions This is conservatively correct, so LGTM. We could do better by using isSafeToSpeculativelyExecute(), but I think you'd have to use that after you've setOperand() and then switch it back if that fails. Or duplicate that logic with the proposed canMergeSelectThroughBinop(). The difference would show up in an example like this where we have a constant divisor, so we know there's no div-by-zero possibility. define i32 @foo(i1 %a, i32 %b, i32 %c) { %sel1 = select i1 %a, i32 42, i32 %b %div = udiv i32 %c, %sel1 %sel2 = select i1 %a, i32 %div, i32 0 ret i32 %sel2 }
|