Pulled out of D109149, this folds set_cc seteq (ashr X, BW-1), -1 -> set_cc setlt X, 0 to prevent some regressions later on when folding select_cc setgt X, -1, C, ~C -> xor (ashr X, BW-1), C
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Looks reasonable to me, but doesn't instcombine pick this up at the IR level? Or don't the .ll test cases run instcombine?
This is part of D109149, it prevents that from causing larger code when this pattern comes up from other DAG Combines.
LGTM.
The motivating transform in D109149 only works on scalars if I'm seeing it correctly. This part could apply to vectors without much effort, but it's already in a FIXME block, so nothing more to do at the moment.
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | ||
---|---|---|
3921 | The comment at line 3914 says we should use "setge" for the "setne" case, but the code actually use "SETGT"? I'm seeing a miscompile with this patch for my out of tree target and I'm not sure what the problem actually is, but the difference between the comment and the code caught my eye. |
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | ||
---|---|---|
3921 | Yes it should definitely be SETGE here! |
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | ||
---|---|---|
3921 | When it goes wrong for me the above code rewrites t22: i32 = sra t20, Constant:i16<31>, foo.c:15:24 t29: i16 = setcc t22, Constant:i32<-1>, setne:ch, foo.c:15:22 into t36: i16 = setcc t20, Constant:i32<0>, setgt:ch, foo.c:15:22 t20 is 0, so t22 is also 0 and t29 is 1. |
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | ||
---|---|---|
3921 | Oh yeah. Does changing it to SETGE fix the miscompile? |
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | ||
---|---|---|
3921 | OK. I'll switch that to the correct thing. Thanks for the report. |
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | ||
---|---|---|
3921 | Yep it does |
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | ||
---|---|---|
3921 | Sounds good! Thanks! |
The comment at line 3914 says we should use "setge" for the "setne" case, but the code actually use "SETGT"?
I'm seeing a miscompile with this patch for my out of tree target and I'm not sure what the problem actually is, but the difference between the comment and the code caught my eye.