Skip to content

Commit 11866c4

Browse files
authored
[DAGCombiner] Don't peek through bitcast when checking isMulAddWithConstProfitable (#171056)
Fixes llvm/llvm-project#171035 Peeking through bitcast may cause type mismatch between `AddNode` and `ConstNode` in `isMulAddWithConstProfitable`.
1 parent f1af9b0 commit 11866c4

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4888,8 +4888,8 @@ template <class MatchContextClass> SDValue DAGCombiner::visitMUL(SDNode *N) {
48884888

48894889
// fold (mul (add x, c1), c2) -> (add (mul x, c2), c1*c2)
48904890
if (sd_context_match(N0, Matcher, m_Opc(ISD::ADD)) &&
4891-
DAG.isConstantIntBuildVectorOrConstantInt(N1) &&
4892-
DAG.isConstantIntBuildVectorOrConstantInt(N0.getOperand(1)) &&
4891+
isConstantOrConstantVector(N1) &&
4892+
isConstantOrConstantVector(N0.getOperand(1)) &&
48934893
isMulAddWithConstProfitable(N, N0, N1))
48944894
return Matcher.getNode(
48954895
ISD::ADD, DL, VT,

llvm/test/CodeGen/RISCV/mul.ll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,3 +2276,31 @@ define i32 @mulor_demand(i32 signext %x, i32 signext %y) nounwind {
22762276
%mul2 = mul i32 %or, 380141568
22772277
ret i32 %mul2
22782278
}
2279+
2280+
define i64 @mul_add_bitcast(i64 %x) {
2281+
; RV32I-LABEL: mul_add_bitcast:
2282+
; RV32I: # %bb.0:
2283+
; RV32I-NEXT: li a0, 0
2284+
; RV32I-NEXT: li a1, 0
2285+
; RV32I-NEXT: ret
2286+
;
2287+
; RV32IM-LABEL: mul_add_bitcast:
2288+
; RV32IM: # %bb.0:
2289+
; RV32IM-NEXT: li a0, 0
2290+
; RV32IM-NEXT: li a1, 0
2291+
; RV32IM-NEXT: ret
2292+
;
2293+
; RV64I-LABEL: mul_add_bitcast:
2294+
; RV64I: # %bb.0:
2295+
; RV64I-NEXT: li a0, 0
2296+
; RV64I-NEXT: ret
2297+
;
2298+
; RV64IM-LABEL: mul_add_bitcast:
2299+
; RV64IM: # %bb.0:
2300+
; RV64IM-NEXT: li a0, 0
2301+
; RV64IM-NEXT: ret
2302+
%add = add i64 %x, 1
2303+
%bitcast = bitcast <2 x i32> zeroinitializer to i64
2304+
%mul = mul i64 %add, %bitcast
2305+
ret i64 %mul
2306+
}

0 commit comments

Comments
 (0)