[X86] Fix missing check of rotate <-> shift equivilence (Issue 108722)
authorNoah Goldstein <goldstein.w.n@gmail.com>
Sun, 15 Sep 2024 16:00:34 +0000 (09:00 -0700)
committerTobias Hieta <tobias@hieta.se>
Tue, 24 Sep 2024 06:28:10 +0000 (08:28 +0200)
Previous code was checking that rotate and shift where equivilent when
transforming shift -> rotate but not the other way around.

Closes #108767

(cherry picked from commit 81279bf97f187eee0446af00d8ae9ec32a22e878)

llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll

index 5a9d679d7002cb1abdc0c2d682367ad65e726dbc..45989bcd07d37e18ee6779e34c8ae54e9359033e 100644 (file)
@@ -3415,7 +3415,7 @@ unsigned X86TargetLowering::preferedOpcodeForCmpEqPiecesOfOperand(
 
   // We prefer rotate for vectors of if we won't get a zext mask with SRL
   // (PreferRotate will be set in the latter case).
-  if (PreferRotate || VT.isVector())
+  if (PreferRotate || !MayTransformRotate || VT.isVector())
     return ShiftOpc;
 
   // Non-vector type and we have a zext mask with SRL.
index 799b5417857575d741dcb238955a236b895e36d8..227de9ad0ab690417b396e0fac67355107ac9f2b 100644 (file)
@@ -997,8 +997,8 @@ define i1 @shr_to_rotate_eq_i32_s5(i32 %x) {
 define i32 @issue108722(i32 %0) {
 ; CHECK-NOBMI-LABEL: issue108722:
 ; CHECK-NOBMI:       # %bb.0:
-; CHECK-NOBMI-NEXT:    movzbl %dil, %ecx
-; CHECK-NOBMI-NEXT:    shrl $24, %edi
+; CHECK-NOBMI-NEXT:    movl %edi, %ecx
+; CHECK-NOBMI-NEXT:    roll $24, %ecx
 ; CHECK-NOBMI-NEXT:    xorl %eax, %eax
 ; CHECK-NOBMI-NEXT:    cmpl %edi, %ecx
 ; CHECK-NOBMI-NEXT:    sete %al