diff --git a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp --- a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp +++ b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp @@ -4007,7 +4007,7 @@ if (Add1C && Add1C->getAPIntValue().urem(Size) == 0) { NewShiftAmt = Add0; - } else if (ShiftAmt->getOpcode() != ISD::ADD && + } else if (ShiftAmt->getOpcode() != ISD::ADD && ShiftAmt.hasOneUse() && ((Add0C && Add0C->getAPIntValue().urem(Size) == Size - 1) || (Add1C && Add1C->getAPIntValue().urem(Size) == Size - 1))) { // If we are doing a NOT on just the lower bits with (Size*N-1) -/^ X diff --git a/llvm/test/CodeGen/X86/pr61038.ll b/llvm/test/CodeGen/X86/pr61038.ll --- a/llvm/test/CodeGen/X86/pr61038.ll +++ b/llvm/test/CodeGen/X86/pr61038.ll @@ -9,42 +9,37 @@ ; CHECK-X64-SKX: # %bb.0: # %entry ; CHECK-X64-SKX-NEXT: tzcntl %eax, %eax ; CHECK-X64-SKX-NEXT: movabsq $8589934591, %rcx # imm = 0x1FFFFFFFF -; CHECK-X64-SKX-NEXT: movq $-1, %rdx +; CHECK-X64-SKX-NEXT: movq %rcx, %rdx ; CHECK-X64-SKX-NEXT: btcq %rax, %rdx -; CHECK-X64-SKX-NEXT: shrxq %rdx, %rcx, %rdx -; CHECK-X64-SKX-NEXT: btcq %rax, %rcx ; CHECK-X64-SKX-NEXT: xorl %eax, %eax -; CHECK-X64-SKX-NEXT: cmpq $64, %rcx -; CHECK-X64-SKX-NEXT: cmovael %eax, %edx -; CHECK-X64-SKX-NEXT: movl %edx, (%rdi) +; CHECK-X64-SKX-NEXT: cmpq $64, %rdx +; CHECK-X64-SKX-NEXT: shrxq %rdx, %rcx, %rcx +; CHECK-X64-SKX-NEXT: cmovael %eax, %ecx +; CHECK-X64-SKX-NEXT: movl %ecx, (%rdi) ; CHECK-X64-SKX-NEXT: retq ; ; CHECK-X64-V4-LABEL: test_61038: ; CHECK-X64-V4: # %bb.0: # %entry ; CHECK-X64-V4-NEXT: tzcntl %eax, %eax ; CHECK-X64-V4-NEXT: movabsq $8589934591, %rcx # imm = 0x1FFFFFFFF -; CHECK-X64-V4-NEXT: movq $-1, %rdx +; CHECK-X64-V4-NEXT: movq %rcx, %rdx ; CHECK-X64-V4-NEXT: btcq %rax, %rdx -; CHECK-X64-V4-NEXT: shrxq %rdx, %rcx, %rdx -; CHECK-X64-V4-NEXT: btcq %rax, %rcx ; CHECK-X64-V4-NEXT: xorl %eax, %eax -; CHECK-X64-V4-NEXT: cmpq $64, %rcx -; CHECK-X64-V4-NEXT: cmovael %eax, %edx -; CHECK-X64-V4-NEXT: movl %edx, (%rdi) +; CHECK-X64-V4-NEXT: cmpq $64, %rdx +; CHECK-X64-V4-NEXT: shrxq %rdx, %rcx, %rcx +; CHECK-X64-V4-NEXT: cmovael %eax, %ecx +; CHECK-X64-V4-NEXT: movl %ecx, (%rdi) ; CHECK-X64-V4-NEXT: retq ; ; CHECK-X64-BMI-LABEL: test_61038: ; CHECK-X64-BMI: # %bb.0: # %entry ; CHECK-X64-BMI-NEXT: tzcntl %eax, %eax ; CHECK-X64-BMI-NEXT: movabsq $8589934591, %rdx # imm = 0x1FFFFFFFF -; CHECK-X64-BMI-NEXT: movq %rdx, %rsi -; CHECK-X64-BMI-NEXT: btcq %rax, %rsi -; CHECK-X64-BMI-NEXT: movq $-1, %rcx +; CHECK-X64-BMI-NEXT: movq %rdx, %rcx ; CHECK-X64-BMI-NEXT: btcq %rax, %rcx -; CHECK-X64-BMI-NEXT: # kill: def $cl killed $cl killed $rcx ; CHECK-X64-BMI-NEXT: shrq %cl, %rdx ; CHECK-X64-BMI-NEXT: xorl %eax, %eax -; CHECK-X64-BMI-NEXT: cmpq $64, %rsi +; CHECK-X64-BMI-NEXT: cmpq $64, %rcx ; CHECK-X64-BMI-NEXT: cmovael %eax, %edx ; CHECK-X64-BMI-NEXT: movl %edx, (%rdi) ; CHECK-X64-BMI-NEXT: retq