[llvm] Fold intrinsics over multi-use selects when the intrinsic is the only user (PR #172723)

Sayan Sivakumaran via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 2 04:01:14 PST 2026


================
@@ -426,3 +426,127 @@ define { <4 x float>, <4 x float> } @test_select_of_sincos_intrinsic_operand(<4
   %result = call { <4 x float>, <4 x float> } @llvm.sincos.v4f32(<4 x float> %s)
   ret { <4 x float>, <4 x float> } %result
 }
+
+define i8 @test_select_rotate_left(i1 %0) {
+; CHECK-LABEL: @test_select_rotate_left(
+; CHECK-NEXT:    [[RET:%.*]] = select i1 [[TMP0:%.*]], i8 2, i8 -1
+; CHECK-NEXT:    ret i8 [[RET]]
+;
+  %s = select i1 %0, i8 1, i8 -1
+  %ret = call i8 @llvm.fshl.i8(i8 %s, i8 %s, i8 1)
+  ret i8 %ret
+}
+
+define i8 @test_select_rotate_left_poison(i1 %0) {
+; CHECK-LABEL: @test_select_rotate_left_poison(
+; CHECK-NEXT:    ret i8 -1
+;
+  %s = select i1 %0, i8 poison, i8 -1
----------------
sivakusayan wrote:

I was originally thinking that this would test against weird cases where we process the `fshl` before the `select` could get simplified. But I see now from `InstCombinerImpl::run` that instructions are processed in source code order, so you're right that this isn't testing anything useful.

https://github.com/llvm/llvm-project/pull/172723


More information about the llvm-commits mailing list