Skip to content

Commit 1b7b4b4

Browse files
committed
[SelectionDAG][Mips][Sparc] Don't allow SimplifyDemandedBits to constant fold TargetConstant nodes to a Constant.
Summary: After the switch in SimplifyDemandedBits, it tries to create a constant when possible. If the original node is a TargetConstant the default in the switch will call computeKnownBits on the TargetConstant which will succeed. This results in the TargetConstant becoming a Constant. But TargetConstant exists to avoid being changed. I've fixed the two cases that relied on this in tree by explicitly making the nodes constant instead of target constant. The Sparc case is an old bug. The Mips case was recently introduced now that ImmArg on intrinsics gets turned into a TargetConstant when the SelectionDAG is created. I've removed the ImmArg since it lowers to generic code. Reviewers: arsenm, RKSimon, spatel Subscribers: jyknight, sdardis, wdng, arichardson, hiraditya, fedor.sergeev, jrtc27, atanasyan, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67802 llvm-svn: 372409
1 parent f6398fb commit 1b7b4b4

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

llvm/include/llvm/IR/IntrinsicsMips.td

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,16 +1260,16 @@ def int_mips_insve_d : GCCBuiltin<"__builtin_msa_insve_d">,
12601260

12611261
def int_mips_ld_b : GCCBuiltin<"__builtin_msa_ld_b">,
12621262
Intrinsic<[llvm_v16i8_ty], [llvm_ptr_ty, llvm_i32_ty],
1263-
[IntrReadMem, IntrArgMemOnly, ImmArg<1>]>;
1263+
[IntrReadMem, IntrArgMemOnly]>;
12641264
def int_mips_ld_h : GCCBuiltin<"__builtin_msa_ld_h">,
12651265
Intrinsic<[llvm_v8i16_ty], [llvm_ptr_ty, llvm_i32_ty],
1266-
[IntrReadMem, IntrArgMemOnly, ImmArg<1>]>;
1266+
[IntrReadMem, IntrArgMemOnly]>;
12671267
def int_mips_ld_w : GCCBuiltin<"__builtin_msa_ld_w">,
12681268
Intrinsic<[llvm_v4i32_ty], [llvm_ptr_ty, llvm_i32_ty],
1269-
[IntrReadMem, IntrArgMemOnly, ImmArg<1>]>;
1269+
[IntrReadMem, IntrArgMemOnly]>;
12701270
def int_mips_ld_d : GCCBuiltin<"__builtin_msa_ld_d">,
12711271
Intrinsic<[llvm_v2i64_ty], [llvm_ptr_ty, llvm_i32_ty],
1272-
[IntrReadMem, IntrArgMemOnly, ImmArg<1>]>;
1272+
[IntrReadMem, IntrArgMemOnly]>;
12731273

12741274
def int_mips_ldi_b : GCCBuiltin<"__builtin_msa_ldi_b">,
12751275
Intrinsic<[llvm_v16i8_ty], [llvm_i32_ty], [IntrNoMem, ImmArg<0>]>;
@@ -1684,16 +1684,16 @@ def int_mips_srlri_d : GCCBuiltin<"__builtin_msa_srlri_d">,
16841684

16851685
def int_mips_st_b : GCCBuiltin<"__builtin_msa_st_b">,
16861686
Intrinsic<[], [llvm_v16i8_ty, llvm_ptr_ty, llvm_i32_ty],
1687-
[IntrArgMemOnly, ImmArg<2>]>;
1687+
[IntrArgMemOnly]>;
16881688
def int_mips_st_h : GCCBuiltin<"__builtin_msa_st_h">,
16891689
Intrinsic<[], [llvm_v8i16_ty, llvm_ptr_ty, llvm_i32_ty],
1690-
[IntrArgMemOnly, ImmArg<2>]>;
1690+
[IntrArgMemOnly]>;
16911691
def int_mips_st_w : GCCBuiltin<"__builtin_msa_st_w">,
16921692
Intrinsic<[], [llvm_v4i32_ty, llvm_ptr_ty, llvm_i32_ty],
1693-
[IntrArgMemOnly, ImmArg<2>]>;
1693+
[IntrArgMemOnly]>;
16941694
def int_mips_st_d : GCCBuiltin<"__builtin_msa_st_d">,
16951695
Intrinsic<[], [llvm_v2i64_ty, llvm_ptr_ty, llvm_i32_ty],
1696-
[IntrArgMemOnly, ImmArg<2>]>;
1696+
[IntrArgMemOnly]>;
16971697

16981698
def int_mips_subs_s_b : GCCBuiltin<"__builtin_msa_subs_s_b">,
16991699
Intrinsic<[llvm_v16i8_ty], [llvm_v16i8_ty, llvm_v16i8_ty], [IntrNoMem]>;

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,8 @@ bool TargetLowering::SimplifyDemandedBits(
805805

806806
KnownBits Known2, KnownOut;
807807
switch (Op.getOpcode()) {
808+
case ISD::TargetConstant:
809+
llvm_unreachable("Can't simplify this node");
808810
case ISD::SCALAR_TO_VECTOR: {
809811
if (!DemandedElts[0])
810812
return TLO.CombineTo(Op, TLO.DAG.getUNDEF(VT));

llvm/lib/Target/Sparc/SparcISelLowering.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,7 +2244,7 @@ SDValue SparcTargetLowering::LowerF128Compare(SDValue LHS, SDValue RHS,
22442244
return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
22452245
}
22462246
case SPCC::FCC_UL : {
2247-
SDValue Mask = DAG.getTargetConstant(1, DL, Result.getValueType());
2247+
SDValue Mask = DAG.getConstant(1, DL, Result.getValueType());
22482248
Result = DAG.getNode(ISD::AND, DL, Result.getValueType(), Result, Mask);
22492249
SDValue RHS = DAG.getTargetConstant(0, DL, Result.getValueType());
22502250
SPCC = SPCC::ICC_NE;
@@ -2277,14 +2277,14 @@ SDValue SparcTargetLowering::LowerF128Compare(SDValue LHS, SDValue RHS,
22772277
return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
22782278
}
22792279
case SPCC::FCC_LG : {
2280-
SDValue Mask = DAG.getTargetConstant(3, DL, Result.getValueType());
2280+
SDValue Mask = DAG.getConstant(3, DL, Result.getValueType());
22812281
Result = DAG.getNode(ISD::AND, DL, Result.getValueType(), Result, Mask);
22822282
SDValue RHS = DAG.getTargetConstant(0, DL, Result.getValueType());
22832283
SPCC = SPCC::ICC_NE;
22842284
return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
22852285
}
22862286
case SPCC::FCC_UE : {
2287-
SDValue Mask = DAG.getTargetConstant(3, DL, Result.getValueType());
2287+
SDValue Mask = DAG.getConstant(3, DL, Result.getValueType());
22882288
Result = DAG.getNode(ISD::AND, DL, Result.getValueType(), Result, Mask);
22892289
SDValue RHS = DAG.getTargetConstant(0, DL, Result.getValueType());
22902290
SPCC = SPCC::ICC_E;

0 commit comments

Comments
 (0)