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,28 +9,24 @@ ; CHECK-BMI2: # %bb.0: # %entry ; CHECK-BMI2-NEXT: tzcntl %eax, %eax ; CHECK-BMI2-NEXT: movabsq $8589934591, %rcx # imm = 0x1FFFFFFFF -; CHECK-BMI2-NEXT: movq $-1, %rdx +; CHECK-BMI2-NEXT: movq %rcx, %rdx ; CHECK-BMI2-NEXT: btcq %rax, %rdx -; CHECK-BMI2-NEXT: shrxq %rdx, %rcx, %rdx -; CHECK-BMI2-NEXT: btcq %rax, %rcx ; CHECK-BMI2-NEXT: xorl %eax, %eax -; CHECK-BMI2-NEXT: cmpq $64, %rcx -; CHECK-BMI2-NEXT: cmovael %eax, %edx -; CHECK-BMI2-NEXT: movl %edx, (%rdi) +; CHECK-BMI2-NEXT: cmpq $64, %rdx +; CHECK-BMI2-NEXT: shrxq %rdx, %rcx, %rcx +; CHECK-BMI2-NEXT: cmovael %eax, %ecx +; CHECK-BMI2-NEXT: movl %ecx, (%rdi) ; CHECK-BMI2-NEXT: retq ; ; CHECK-BMI-LABEL: test_61038: ; CHECK-BMI: # %bb.0: # %entry ; CHECK-BMI-NEXT: tzcntl %eax, %eax ; CHECK-BMI-NEXT: movabsq $8589934591, %rdx # imm = 0x1FFFFFFFF -; CHECK-BMI-NEXT: movq %rdx, %rsi -; CHECK-BMI-NEXT: btcq %rax, %rsi -; CHECK-BMI-NEXT: movq $-1, %rcx +; CHECK-BMI-NEXT: movq %rdx, %rcx ; CHECK-BMI-NEXT: btcq %rax, %rcx -; CHECK-BMI-NEXT: # kill: def $cl killed $cl killed $rcx ; CHECK-BMI-NEXT: shrq %cl, %rdx ; CHECK-BMI-NEXT: xorl %eax, %eax -; CHECK-BMI-NEXT: cmpq $64, %rsi +; CHECK-BMI-NEXT: cmpq $64, %rcx ; CHECK-BMI-NEXT: cmovael %eax, %edx ; CHECK-BMI-NEXT: movl %edx, (%rdi) ; CHECK-BMI-NEXT: retq