[llvm] 11866c4 - [DAGCombiner] Don't peek through bitcast when checking isMulAddWithConstProfitable (#171056)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 8 06:09:17 PST 2025
Author: Hongyu Chen
Date: 2025-12-08T22:09:12+08:00
New Revision: 11866c499b06ae2f259ef870c8ea15c560bee04d
URL: https://github.com/llvm/llvm-project/commit/11866c499b06ae2f259ef870c8ea15c560bee04d
DIFF: https://github.com/llvm/llvm-project/commit/11866c499b06ae2f259ef870c8ea15c560bee04d.diff
LOG: [DAGCombiner] Don't peek through bitcast when checking isMulAddWithConstProfitable (#171056)
Fixes https://github.com/llvm/llvm-project/issues/171035
Peeking through bitcast may cause type mismatch between `AddNode` and
`ConstNode` in `isMulAddWithConstProfitable`.
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/RISCV/mul.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 126867a6eac96..3366b8a75a6d9 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -4888,8 +4888,8 @@ template <class MatchContextClass> SDValue DAGCombiner::visitMUL(SDNode *N) {
// fold (mul (add x, c1), c2) -> (add (mul x, c2), c1*c2)
if (sd_context_match(N0, Matcher, m_Opc(ISD::ADD)) &&
- DAG.isConstantIntBuildVectorOrConstantInt(N1) &&
- DAG.isConstantIntBuildVectorOrConstantInt(N0.getOperand(1)) &&
+ isConstantOrConstantVector(N1) &&
+ isConstantOrConstantVector(N0.getOperand(1)) &&
isMulAddWithConstProfitable(N, N0, N1))
return Matcher.getNode(
ISD::ADD, DL, VT,
diff --git a/llvm/test/CodeGen/RISCV/mul.ll b/llvm/test/CodeGen/RISCV/mul.ll
index d691b1c278a48..263eeec1289b2 100644
--- a/llvm/test/CodeGen/RISCV/mul.ll
+++ b/llvm/test/CodeGen/RISCV/mul.ll
@@ -2276,3 +2276,31 @@ define i32 @mulor_demand(i32 signext %x, i32 signext %y) nounwind {
%mul2 = mul i32 %or, 380141568
ret i32 %mul2
}
+
+define i64 @mul_add_bitcast(i64 %x) {
+; RV32I-LABEL: mul_add_bitcast:
+; RV32I: # %bb.0:
+; RV32I-NEXT: li a0, 0
+; RV32I-NEXT: li a1, 0
+; RV32I-NEXT: ret
+;
+; RV32IM-LABEL: mul_add_bitcast:
+; RV32IM: # %bb.0:
+; RV32IM-NEXT: li a0, 0
+; RV32IM-NEXT: li a1, 0
+; RV32IM-NEXT: ret
+;
+; RV64I-LABEL: mul_add_bitcast:
+; RV64I: # %bb.0:
+; RV64I-NEXT: li a0, 0
+; RV64I-NEXT: ret
+;
+; RV64IM-LABEL: mul_add_bitcast:
+; RV64IM: # %bb.0:
+; RV64IM-NEXT: li a0, 0
+; RV64IM-NEXT: ret
+ %add = add i64 %x, 1
+ %bitcast = bitcast <2 x i32> zeroinitializer to i64
+ %mul = mul i64 %add, %bitcast
+ ret i64 %mul
+}
More information about the llvm-commits
mailing list