This combine makes two calls to SimplifyDemandedBits, one for the LHS and one for the RHS. If the LHS call returns true, we don't make the RHS call. When SimplifyDemandedBits makes a change, it will add the nodes around the change to the DAG combiner worklist. If the simplification happens on the first recursion step, the N will get added to the worklist. But if the simplification happens deeper in the recursion, then N will not be revisited until the next time the DAG combiner runs. This patch explicitly addes N to the worklist anytime a Simplification is made. Without this we might miss additional simplifications on the LHS or never simplify the RHS. Special care also needs to be taken to not add N if it has been CSEd by the simplification. There are similar examples in DAGCombiner and the X86 target, but I don't have a test for it for RISC-V. I've also returned SDValue(N, 0) instead of SDValue() so DAGCombiner knows a change was made and will update its Statistic variable. The test here was constructed so that 2 simplifications happen to the LHS. Without this fix one happens in the post type legalization DAG combine and the other happens after LegalizeDAG. This prevents the RHS from ever being simplified causing the left and right shift to clear the upper 32 bits of the RHS to be left behind. Differential Revision: https://reviews.llvm.org/D90339
27 lines
902 B
LLVM
27 lines
902 B
LLVM
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
|
|
; RUN: llc -mtriple=riscv64 -mattr=+m -verify-machineinstrs < %s | FileCheck %s
|
|
|
|
; This test has multiple opportunities for SimplifyDemandedBits after type
|
|
; legalization. There are 2 opportunities on the chain feeding the LHS of the
|
|
; shl. And one opportunity on the shift amount. We previously weren't managing
|
|
; the DAGCombiner worklist correctly and failed to get the RHS.
|
|
|
|
define i32 @foo(i32 %x, i32 %y, i32 %z) {
|
|
; CHECK-LABEL: foo:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: mulw a0, a0, a0
|
|
; CHECK-NEXT: addi a0, a0, 1
|
|
; CHECK-NEXT: mul a0, a0, a0
|
|
; CHECK-NEXT: add a0, a0, a2
|
|
; CHECK-NEXT: addi a0, a0, 1
|
|
; CHECK-NEXT: sllw a0, a0, a1
|
|
; CHECK-NEXT: ret
|
|
%b = mul i32 %x, %x
|
|
%c = add i32 %b, 1
|
|
%d = mul i32 %c, %c
|
|
%e = add i32 %d, %z
|
|
%f = add i32 %e, 1
|
|
%g = shl i32 %f, %y
|
|
ret i32 %g
|
|
}
|