File tree Expand file tree Collapse file tree 3 files changed +13
-3
lines changed
lib/Transforms/InstCombine
test/Transforms/InstCombine Expand file tree Collapse file tree 3 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -113,6 +113,12 @@ struct SimplifyQuery {
113
113
using namespace PatternMatch ;
114
114
return match (V, m_Undef ());
115
115
}
116
+
117
+ SimplifyQuery getWithoutDomCondCache () const {
118
+ SimplifyQuery Copy (*this );
119
+ Copy.DC = nullptr ;
120
+ return Copy;
121
+ }
116
122
};
117
123
118
124
} // end namespace llvm
Original file line number Diff line number Diff line change @@ -2281,8 +2281,10 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator &I) {
2281
2281
if (match (Op0, m_APInt (Op0C))) {
2282
2282
if (Op0C->isMask ()) {
2283
2283
// Turn this into a xor if LHS is 2^n-1 and the remaining bits are known
2284
- // zero.
2285
- KnownBits RHSKnown = computeKnownBits (Op1, 0 , &I);
2284
+ // zero. We don't use information from dominating conditions so this
2285
+ // transform is easier to reverse if necessary.
2286
+ KnownBits RHSKnown = llvm::computeKnownBits (
2287
+ Op1, 0 , SQ.getWithInstruction (&I).getWithoutDomCondCache ());
2286
2288
if ((*Op0C | RHSKnown.Zero ).isAllOnes ())
2287
2289
return BinaryOperator::CreateXor (Op1, Op0);
2288
2290
}
Original file line number Diff line number Diff line change @@ -158,13 +158,15 @@ define <2 x i8> @xor_add_splat_undef(<2 x i8> %x) {
158
158
ret <2 x i8 > %add
159
159
}
160
160
161
+ ; Make sure we don't convert sub to xor using dominating condition. That makes
162
+ ; it hard for other passe to reverse.
161
163
define i32 @xor_dominating_cond (i32 %x ) {
162
164
; CHECK-LABEL: @xor_dominating_cond(
163
165
; CHECK-NEXT: entry:
164
166
; CHECK-NEXT: [[COND:%.*]] = icmp ult i32 [[X:%.*]], 256
165
167
; CHECK-NEXT: br i1 [[COND]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
166
168
; CHECK: if.then:
167
- ; CHECK-NEXT: [[A:%.*]] = xor i32 [[X]], 255
169
+ ; CHECK-NEXT: [[A:%.*]] = sub nuw nsw i32 255, [[X]]
168
170
; CHECK-NEXT: ret i32 [[A]]
169
171
; CHECK: if.end:
170
172
; CHECK-NEXT: ret i32 [[X]]
You can’t perform that action at this time.
0 commit comments