-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Thumb] Resolve FIXME: Transform "(and (shl x, c2), c1)" into "(shl (and x, c1>>c2), c2)" #82120
Conversation
@llvm/pr-subscribers-backend-arm Author: AtariDreams (AtariDreams) ChangesTransform "(and (shl x, c2) c1)" into "(shl (and x, c1>>c2), c2)" if "c1 >> c2" is a cheaper immediate than "c1" using HasLowerConstantMaterializationCost. Full diff: https://github.com/llvm/llvm-project/pull/82120.diff 1 Files Affected:
diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp
index b98006ed0cb3f4..4d92add3738e29 100644
--- a/llvm/lib/Target/ARM/ARMISelLowering.cpp
+++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp
@@ -14388,9 +14388,16 @@ static SDValue CombineANDShift(SDNode *N,
}
}
- // FIXME: Transform "(and (shl x, c2) c1)" ->
- // "(shl (and x, c1>>c2), c2)" if "c1 >> c2" is a cheaper immediate than
- // c1.
+ // Transform "(and (shl x, c2) c1)" into "(shl (and x, c1>>c2), c2)"
+ // if "c1 >> c2" is a cheaper immediate than "c1"
+ if (HasLowerConstantMaterializationCost(C1 >> C2, C1, Subtarget)) {
+
+ SDValue And = DAG.getNode(ISD::AND, DL, MVT::i32, N0->getOperand(0),
+ DAG.getConstant(C1 >> C2, DL, MVT::i32));
+ return DAG.getNode(ISD::SHL, DL, MVT::i32, And,
+ DAG.getConstant(C2, DL, MVT::i32));
+ }
+
return SDValue();
}
|
|
bbdd15d
to
d2471d0
Compare
f8dabd3
to
da08a13
Compare
@topperc Thoughts? |
ff24fe7
to
ff231b8
Compare
@topperc Thoughts? |
I think this one looks reasonable to me. Logic seems to check out and it looks for benefits before proceeding. |
@RKSimon what do you think about merging this? |
…and x, c1>>c2), c2)" Transform "(and (shl x, c2), c1)" into "(shl (and x, c1>>c2), c2)" if "c1 >> c2" is a cheaper immediate than "c1" using HasLowerConstantMaterializationCost.
I don't think its necessary - we're up top 18.1.6 now and this is a perf improvement, not a critical bugfix for a recent issue. Better to focus on getting trunk ready for 19.X in a couple of months time. |
This wasn't proposed for 18.x @RKSimon. |
Sorry, misunderstood your question |
Transform "(and (shl x, c2), c1)" into "(shl (and x, c1>>c2), c2)" if "c1 >> c2" is a cheaper immediate than "c1" using HasLowerConstantMaterializationCost.