@@ -3233,21 +3233,35 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
3233
3233
if (!RK || RK.AttrKind != Attribute::Alignment ||
3234
3234
!isPowerOf2_64 (RK.ArgValue ))
3235
3235
continue ;
3236
- SetVector<const Instruction *> WorkList;
3236
+ SetVector<const Value *> WorkList;
3237
3237
bool AlignNeeded = false ;
3238
- WorkList.insert (II);
3238
+ for (const User *U : RK.WasOn ->users ())
3239
+ WorkList.insert (cast<Instruction>(U));
3240
+
3239
3241
for (unsigned I = 0 ; I != WorkList.size (); ++I) {
3240
- if (auto *LI = dyn_cast<LoadInst>(WorkList[I])) {
3242
+ auto *Curr = WorkList[I];
3243
+ if (auto *LI = dyn_cast<LoadInst>(Curr)) {
3241
3244
if (auto *AlignMD = LI->getMetadata (LLVMContext::MD_align)) {
3242
3245
auto *A = mdconst::extract<ConstantInt>(AlignMD->getOperand (0 ));
3243
3246
3244
3247
if (A->getZExtValue () % RK.ArgValue != 0 ) {
3245
3248
AlignNeeded = true ;
3246
3249
break ;
3247
3250
}
3251
+
3252
+ if (LI->getAlign ().value () < RK.ArgValue ) {
3253
+ AlignNeeded = true ;
3254
+ break ;
3255
+ }
3256
+ }
3257
+ }
3258
+ if (auto *SI = dyn_cast<StoreInst>(Curr)) {
3259
+ if (SI->getAlign ().value () < RK.ArgValue ) {
3260
+ AlignNeeded = true ;
3261
+ break ;
3248
3262
}
3249
3263
}
3250
- if (isa<ICmpInst>(WorkList[I] )) {
3264
+ if (isa<ICmpInst>(Curr) && !isa<Constant>(cast<Instruction>(Curr)-> getOperand ( 0 )) && !isa<Constant>(cast<Instruction>(Curr)-> getOperand ( 1 ) )) {
3251
3265
AlignNeeded = true ;
3252
3266
break ;
3253
3267
}
@@ -3256,11 +3270,13 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
3256
3270
break ;
3257
3271
}
3258
3272
3259
- for (const User *U : WorkList[I] ->users ())
3273
+ for (const User *U : Curr ->users ())
3260
3274
WorkList.insert (cast<Instruction>(U));
3261
3275
}
3262
- auto *New = CallBase::removeOperandBundle (II, OBU.getTagID ());
3263
- return New;
3276
+ if (!AlignNeeded) {
3277
+ auto *New = CallBase::removeOperandBundle (II, OBU.getTagID ());
3278
+ return New;
3279
+ }
3264
3280
}
3265
3281
}
3266
3282
0 commit comments