<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">There's a question about the behavior of funnel shift [1] + select and poison here that reminds me of previous discussions about select and poison [2]:<br><a href="https://github.com/AliveToolkit/alive2/pull/32#discussion_r257528880">https://github.com/AliveToolkit/alive2/pull/32#discussion_r257528880</a><br><br>Example:<br>define i8 @fshl_zero_shift_guard(i8 %x, i8 %y, i8 %sh) {<br>%c = icmp eq i8 %sh, 0<br>%f = fshl i8 %x, i8 %y, i8 %sh<br>%s = select i1 %c, i8 %x, i8 %f ; shift amount is 0 returns x (same as fshl)<br>ret i8 %s<br>}<br>=><br>define i8 @fshl_zero_shift_guard(i8 %x, i8 %y, i8 %sh) {<br>%f = fshl i8 %x, i8 %y, i8 %sh<br>ret i8 %f<br>}<br>Transformation doesn't verify!<br>ERROR: Target is more poisonous than source<br></div><div dir="ltr"><br></div><div dir="ltr">----------------------------------------------------------------------------</div><div dir="ltr"><br></div><div dir="ltr">The problem is that if %y is poison and we assume that funnel shift uses all of its operands unconditionally, the reduced code sees poison while the original code is protected by the "conditional poison" (terminology?) property of a select op and is safe.<br><br>If we treat funnel shift more like a select based on its operation (when the shift amount is 0, we know that the output is exactly 1 of the inputs), then the transform should be allowed?<br><br>This transform was implemented in instcombine [3] with the motivation of reducing UB-safe rotate code in C to the LLVM intrinsic [4]. So a potential sidestep of the problem would be to limit that transform to a rotate pattern (single value is being shifted) rather than the more general funnel pattern (two values are being shifted).<br><br>[1] <a href="https://llvm.org/docs/LangRef.html#llvm-fshl-intrinsic">https://llvm.org/docs/LangRef.html#llvm-fshl-intrinsic</a><br>[2] <a href="http://llvm.1065342.n5.nabble.com/poison-and-select-td72262.html">http://llvm.1065342.n5.nabble.com/poison-and-select-td72262.html</a><br>[3] <a href="https://reviews.llvm.org/D54552">https://reviews.llvm.org/D54552</a><br>[4] <a href="https://bugs.llvm.org/show_bug.cgi?id=34924">https://bugs.llvm.org/show_bug.cgi?id=34924</a><div><br></div></div></div></div></div></div></div></div></div>